《Efficient Deep Learning Book》[EDL] Chapter 7 - Automationopt.apply_gradients(zip(grads, model.trainable_variables)) losses.append(loss.numpy()) min_loss = np.min(losses) search_results.append(min_loss) fmt = 'Trial: {} learning_rate: {} layer_size: {} loss: blocks = [] for block in cell_config: block_output = self.compose_block(block, inputs) blocks.append(block_output) x = tf.concat(blocks, -1) output = self.repair_channels(x) return output The CNNCell() past_accuracies = deque( maxlen=CHILD_PARAMS['rolling_accuracies_window'] ) self.past_accuracies.append(DATASET_PARAMS['baseline_accuracy']) self.layers = [(0, 1), (1, 2), (0, 1), (1, 2), (0, 1)] def0 码力 | 33 页 | 2.48 MB | 1 年前3
AI大模型千问 qwen 中文文档c['messages'] text = tokenizer.apply_chat_template(msg, tokenize=False, add_generation_ �→prompt=False) data.append(text.strip()) 其中每个 msg 是一个典型的聊天消息,如下所示: [ {"role": "system", "content": "You are a helpful assistant tokenizer([text]) input_ids = torch.tensor(model_inputs.input_ids[:max_len], dtype=torch.int) data.append(dict(input_ids=input_ids, attention_mask=input_ids.ne(tokenizer.pad_ �→token_id))) 接下来,你需要准备数据 """Preprocesses the data for supervised fine-tuning.""" texts = [] for i, msg in enumerate(messages): texts.append( tokenizer.apply_chat_template( msg, tokenize=True, add_generation_prompt=False, padding=True, max_length=max_len0 码力 | 56 页 | 835.78 KB | 1 年前3
动手学深度学习 v2.0start(self): """启动计时器""" self.tik = time.time() def stop(self): """停止计时器并将时间记录在列表中""" self.times.append(time.time() - self.tik) return self.times[-1] def avg(self): """返回平均时间""" return sum(self.times) for i, (a, b) in enumerate(zip(x, y)): if a is not None and b is not None: self.X[i].append(a) self.Y[i].append(b) self.axes[0].cla() for x, y, fmt in zip(self.X, self.Y, self.fmts): self.axes[0] loss(net(X), y) l.backward() optimizer.step() train_ls.append(log_rmse(net, train_features, train_labels)) if test_labels is not None: test_ls.append(log_rmse(net, test_features, test_labels)) return train_ls0 码力 | 797 页 | 29.45 MB | 1 年前3
全连接神经网络实战. pytorch 版[ 1 ] = idata [ 1 ] ∗ 2 l a b e l . append (0) e l s e : # 把 大 于 0 .5 的 值 压 缩 到 [ 4 , 5 ] 之 间 idata [ 1 ] = ( idata [ 1 ] − 0.5) ∗ 2.0 + 4.0 l a b e l . append (1) e l s e : # 把 大 于0 .5 的 值 压 缩 到 [ 1 ] = idata [ 1 ] ∗ 2 l a b e l . append (2) e l s e : # 把 大 于 0 .5 的 值 压 缩 到 [ 4 , 5 ] 之 间 idata [ 1 ] = ( idata [ 1 ] − 0.5) ∗ 2.0 + 4.0 l a b e l . append (3) data = np . random . rand (20000 Chapter 4. 构建自己的数据集 23 correctCurve = [ ] 然后在 test_loop 函数中把每次计算好的 correct 假如该列表: correctCurve . append ( correct ∗ 100.0) 生成轮数横坐标: count = l i s t ( range ( epochs ) ) count = [ i + 1 for i in count0 码力 | 29 页 | 1.40 MB | 1 年前3
【PyTorch深度学习-龙龙老师】-测试版202112eps = np.random.normal(0., 0.01) # 得到模型的输出 y = 1.477 * x + 0.089 + eps data.append([x, y]) # 保存样本点 data = np.array(data) # 转换为 2D Numpy 数组 通过 for 循环进行 100 次采样,每次从均匀分布?(−1 ,1 )中随机采样一个数据 range(-8,8,100): # 循环生成 y 坐标,100 个采样点 z = sinc(x,y) # 计算每个点(x,y)处的 sinc 函数值 points.append([x,y,z]) # 保存采样点 很明显这种串行采样方式效率极低,那么有没有简洁高效地方式生成网格坐标呢?答案是 肯定的,meshgrid 函数即可实现。 图 5.5 Sinc 函数 _layers = [] # 网络层对象列表 def add_layer(self, layer): # 追加网络层 self._layers.append(layer) 网络的前向传播只需要循环调各个网络层对象的前向计算函数即可,代码如下: def feed_forward(self, X): # 前向传播0 码力 | 439 页 | 29.91 MB | 1 年前3
《Efficient Deep Learning Book》[EDL] Chapter 3 - Learning Techniquestransformed_words = [] for word in words: if word in candidates: transformed_words.append(synonym_or_self(word)) else: transformed_words.append(word) return transformed_words syn_transformation(words, candidates)0 码力 | 56 页 | 18.93 MB | 1 年前3
Keras: 基于 Python 的深度学习库min_lr: 学习速率的下边界。 11.1.12 CSVLogger [source] keras.callbacks.CSVLogger(filename, separator=',', append=False) 把训练轮结果数据流到 csv 文件的回调函数。 支持所有可以被作为字符串表示的值,包括 1D 可迭代数据,例如,np.ndarray。 例 csv_logger = CSVLogger('training callbacks=[csv_logger]) 参数 • filename: csv 文件的文件名,例如’run/log.csv’。 • separator: 用来隔离 csv 文件中元素的字符串。 • append: True:如果文件存在则增加(可以被用于继续训练)。False:覆盖存在的文件。 11.1.13 LambdaCallback [source] keras.callbacks.Lamb on_train_begin(self, logs={}): self.losses = [] def on_batch_end(self, batch, logs={}): self.losses.append(logs.get('loss')) 11.2.1 例: 记录损失历史 class LossHistory(keras.callbacks.Callback): def on_train_begin(self0 码力 | 257 页 | 1.19 MB | 1 年前3
Machine Learning Pytorch Tutorialtt_set: x = x.to(device) with torch.no_grad(): pred = model(x) preds.append(pred.cpu()) set model to evaluation mode iterate through the dataloader move data to device (cpu/cuda)0 码力 | 48 页 | 584.86 KB | 1 年前3
《Efficient Deep Learning Book》[EDL] Chapter 4 - Efficient Architecturesvocab): text_items = [] for item in items: text_item = [vocab[token] for token in item] text_items.append(text_item) return text_items def get_attention_scores(text): # Extract embedding and attention0 码力 | 53 页 | 3.92 MB | 1 年前3
共 9 条
- 1













