File 1: semi_supervised\main.py 1. Lines 286-287: Detailed Non-English Lines: Line 286: flush()的作用是刷新缓冲区。 Line 287: 缓冲区的刷新有三种:1,缓冲区满自动刷新;2,flush刷新;3,程序结束自动刷新 Translation (English): The role of flush() is to flush the buffer. There are three ways to refresh the buffer: 1. Automatic refresh when the buffer is full; 2. Manual refresh via flush(); 3. Automatic refresh upon program termination. 2. Line 321: Detailed Non-English Lines: Line 321: train_acc * 100, acc * 100, std * 100, round(duration, 2)) # round() 方法返回浮点数x的四舍五入值。 Translation (English): The round() method returns the rounded value of floating-point number x. File 2: transfer\chem_model.py 1. Lines 443-453: Detailed Non-English Lines: Line 443: 函数格式为:torch.load(f, map_location=None, pickle_module=pickle, **pickle_load_args)一般我们使用的时候,基本只使用前两个参数。 Line 444: map_location参数: 具体来说,map_location参数是用于重定向,比如此前模型的参数是在cpu中的,我们希望将其加载到cuda:0中。或者我们有多张卡,那么我们就可以将卡1中训练好的模型加载到卡2中,这在数据并行的分布式深度学习中可能会用到。 Line 446: 不指定map_location,默认以训练保存模型时的位置加载,也就是训练在cuda:0,在不指定map_location时,load也是在cuda:0上,相应的训练在cuda:1,那么load也在cuda:1上 Line 447: (2)map_location=cpu 将模型参数加载在CPU上 Line 449: 在pytorch中构建好一个模型后,一般需要将torch.load()的预训练权重加载到自己的模型重。 Line 450: torch.load_state_dict()函数就是用于将预训练的参数权重加载到新的模型之中 Line 451: 在load_state_dict中,我们重点关注的是属性 strict,当strict=True,要求预训练权重层数的键值与新构建的模型中的权重层数名称 Line 452: 完全吻合;如果新构建的模型在层数上进行了部分微调,则上述代码就会报错:说key对应不上。 Line 453: 此时,如果我们采用strict=False 就能够完美的解决这个问题。与训练权重中与新构建网络中匹配层的键值就进行使用,没有的就默认初始化。 Translation (English): The function format is: torch.load(f, map_location=None, pickle_module=pickle, **pickle_load_args). Typically, we only use the first two parameters in practice. The map_location parameter: Specifically, the map_location parameter is used for redirection. For example, if the model parameters were originally on CPU, we might want to load them onto cuda:0. Or if we have multiple GPUs, we can load a model trained on GPU 1 onto GPU 2, which might be useful in data-parallel distributed deep learning scenarios. (1) If map_location is not specified, it defaults to loading the model at the same location where it was saved during training. That is, if training was on cuda:0, loading will also be on cuda:0 when map_location is unspecified. Similarly, if training was on cuda:1, loading will be on cuda:1. (2) map_location=cpu loads the model parameters onto CPU. After building a model in PyTorch, we generally need to load pretrained weights from torch.load() into our own model. The torch.load_state_dict() function is used to load pretrained parameter weights into a new model. In load_state_dict, we primarily focus on the strict attribute. When strict=True, it requires that the key names of the pretrained weights layers must exactly match those in the newly constructed model. If the new model has been partially modified at the layer level, the code will report an error about mismatched keys. In such cases, using strict=False perfectly solves this problem. It will use matching layer keys between the pretrained weights and the new network, while default-initializing any unmatched layers. 2. Line 456: Detailed Non-English Lines: Line 456: self.gnn.load_state_dict(torch.load(model_file, map_location=device)) #加载模型 Translation (English): load model File 3: unsupervised\train.py ---------------------------------------- 1. Line 122: Detailed Non-English Lines: Line 122: loss_a = - torch.log(loss_a).mean() # 全部 Translation (English): all File 4: unsupervised\us_aug.py 1. Lines 81-85: Detailed Non-English Lines: Line 81: # 所有边的源节点 Line 83: # edge的边数 193062 Line 85: #得到所有具有边的节点----------不懂 Translation (English): Source nodes of all edges Number of edges: 193062 Get all nodes that have edges ---------- Don't understand 2. Line 178: Detailed Non-English Lines: Line 178: def get_num_feature(self):#特征数 Translation (English): number of features 3. Line 222: Detailed Non-English Lines: Line 222: sl = torch.tensor([[n,n] for n in range(node_num)]).t() #自循环 Translation (English): self-loop File 5: unsupervised\us_evaluate_embedding.py 1. Lines 8-14: Detailed Non-English Lines: Line 8: n_splitsint,默认值 = 5 Line 9: 折叠数。必须至少为 2。 Line 10: shuffle布尔值,默认值=假 Line 11: 是否在拆分为批次之前随机排列每个类的样本。 请注意,每个拆分中的样本不会被随机排列。 Line 12: random_stateint、随机状态实例或无,默认值 = 无 当为 True 时,会影响 索引,用于控制每个类的每个折叠的随机性。 Line 13: 否则,保留为 。 传递一个 int 以获得跨多个函数调用的可重现输出。 请参阅词汇表。shufflerandom_staterandom_stateNone Line 14: StratifiedKFold用法类似Kfold,但是他是分层采样,确保训练集,测试集中各类别样本的比例与原始数据集中相同 Translation (English): n_splits: int, default=5 Number of folds. Must be at least 2. shuffle: bool, default=False Whether to shuffle the samples of each class before splitting into batches. Note that samples within each split will not be shuffled. random_state: int, RandomState instance or None, default=None When shuffle is True, this affects the index ordering to control randomness for each class in each fold. Otherwise, it remains None. Pass an int for reproducible output across multiple function calls. See Glossary. StratifiedKFold operates similarly to KFold but performs stratified sampling, ensuring that the proportion of samples from each class in the training and test sets matches that of the original dataset. 2. Lines 19-23: Detailed Non-English Lines: Line 19: (1)estimator选择使用的分类器,并且传入除需要确定最佳的参数之外的其他参数。每一个分类器都需要一个scoring参数,或者score方法:estimator=RandomForestClassifier(min_samples_split=100,min_samples_leaf=20,max_depth=8,max_features='sqrt',random_state=10), Line 21: 需要最优化的参数的取值,值为字典或者列表,例如:param_grid =param_test1,param_test1 = {'n_estimators':range(10,71,10)}。 Line 23: 模型评价标准,默认None,这时需要使用score函数;或者如scoring='roc_auc',根据所选模型不同,评价准则不同。字符串(函数名),或是可调用对象,需要其函数签名形如:scorer(estimator, X, y);如果是None,则使用estimator的误差估计函数。具体值的选取看本篇第三节内容。 Translation (English): (1) The `estimator` selects the classifier to be used and passes in other parameters besides those that need to determine the optimal values. Each classifier requires either a `scoring` parameter or a score method, e.g.: `estimator=RandomForestClassifier(min_samples_split=100,min_samples_leaf=20,max_depth=8,max_features='sqrt',random_state=10)`. The values of parameters to be optimized should be provided as a dictionary or list, for example: `param_grid = param_test1`, where `param_test1 = {'n_estimators':range(10,71,10)}`. The model evaluation metric defaults to None, in which case the score function must be used. Alternatively, metrics like `scoring='roc_auc'` can be specified, with different evaluation criteria depending on the selected model. This can be either a string (function name) or a callable object requiring a function signature like: `scorer(estimator, X, y)`. If None, the estimator's error estimation function will be used. Refer to Section 3 of this article for specific value selection. 3. Lines 26-36: Detailed Non-English Lines: Line 26: n_jobs: 并行数,int:个数,-1:跟CPU核数一致, 1:默认值 Line 28: iid:默认True,为True时,默认为各个样本fold概率分布一致,误差估计为所有样本之和,而非各个fold的平均。 Line 30: 默认为True,程序将会以交叉验证训练集得到的最佳参数,重新对所有可用的训练集与开发集进行,作为最终用于性能评估的最佳模型参数。即在搜索参数结束后,用最佳参数结果再次fit一遍全部数据集。 Line 32: 交叉验证参数,默认None,使用三折交叉验证。指定fold数量,默认为3,也可以是yield训练/测试数据的生成器。 Line 34: verbose:日志冗长度,int:冗长度,0:不输出训练过程,1:偶尔输出,>1:对每个子模型都输出。 Line 36: 指定总共分发的并行任务数。当n_jobs大于1时,数据将在每个运行点进行复制,这可能导致OOM,而设置pre_dispatch参数,则可以预先划分总共的job数量,使数据最多被复制pre_dispatch次 Translation (English): n_jobs: Number of parallel jobs, int: count, -1: matches CPU cores, 1: default value iid: Default is True. When True, assumes identical probability distribution across sample folds, with error estimated as the sum of all samples rather than the average of individual folds. Default is True. The program will use the best parameters obtained from cross-validated training sets to refit all available training and development sets, serving as the final best model parameters for performance evaluation. That is, after parameter search completes, the best parameters are used to fit the entire dataset again. Cross-validation parameter, default is None, using 3-fold cross-validation. Specifies the number of folds (default is 3) or can be a generator yielding train/test data. verbose: Log verbosity, int: verbosity level, 0: no training process output, 1: occasional output, >1: output for every sub-model. Specifies the total number of parallel jobs to dispatch. When n_jobs > 1, data may be replicated at each execution point, potentially causing OOM. Setting pre_dispatch pre-allocates the total job count, limiting data replication to pre_dispatch times at most. 4. Lines 39-40: Detailed Non-English Lines: Line 39: 如果“False”,cv_results_属性将不包括训练分数 Line 40: 回到sklearn里面的GridSearchCV,GridSearchCV用于系统地遍历多种参数组合,通过交叉验证确定最佳效果参数 Translation (English): If "False", the cv_results_ attribute will not include training scores. Returning to GridSearchCV in sklearn, GridSearchCV is used to systematically traverse multiple parameter combinations and determine the optimal parameters through cross-validation. 5. Line 87: Detailed Non-English Lines: Line 87: params = {'C':[0.001, 0.01,0.1,1,10,100,1000]}#优化的参数取值 Translation (English): Parameter values for optimization File 6: unsupervised\us_gin.py 1. Line 54: Detailed Non-English Lines: Line 54: x, _ = self.forward(x, edge_index, batch) #图级 Translation (English): graph-level