当前位置:网站首页>Hugging face 的问题记录 I
Hugging face 的问题记录 I
2022-07-28 05:24:00 【SCHLAU_tono】
Error 1.
Torch.utils.datasets和huggingface的datasets是不一样的
Error 2. cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
准确来说,这不是Hugging face的问题,是我在使用Torch时遇到的问题,现在也收集其中
出现的原因主要时CUDA runtime version不合适,解决方案参考帖子:
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
Error 3. vars() argument must have dict attribute?
这个问题出现的原因多半是因为使用了自定义的dataset,但是在训练模型的时候没有传入相对于的data_collator
问题代码如下:
encoded_texts = tokenizer(texts, padding = True, truncation = True, return_tensors = 'pt')
labels = torch.tensor(labels)
dataset = TensorDataset(encoded_texts['input_ids'], encoded_texts['attention_mask'], labels)
这里的dataset的类型是torch.util.dataset, trainer默认认为传入的dataset是datasets ,所以使用默认的default_data_collator提取数据。
解决方法:自定义data_collator函数然后加入TrainingArguments中。代码如下:
customised_data_collector(features):
batch = {
}
batch['input_ids'] = torch.stack([f[0] for f in features])
batch['attention_mask'] = torch.stack([f[1] for f in features])
batch['labels'] = torch.stack([f[2] for f in features])
return batch
################
TrainingArguments(..., data_collator=customised_data_collector ,...)
参考帖子
Error 4. TypeError: forward() got an unexpected keyword argument ‘label’
这个错误的原因比较复杂,而且我最终也没能直接解决这个问题。这里只记录一些可能性比较高的原因以及解决方法:
- 有些模型的参数名是
labels而不是label. 解决方法用datasets.rename_column("label", "labels")更改名字 - Jupyter Notebook 自身发疯,重启内核重新运行就好。参考帖子
- 有一些model例如
MT5EncoderModel和T5EncoderModel只是基础模型,没有label参数。参考模型源码forward(). 如果需要Sequence classification。则需要自定义Model,参考BertForSequenceClassification的实现源码
如何在Colab中加载Google Drive的文件.
该文章详细介绍了七种加载Google drive的方式。我采用其中第六种方式,装载硬盘到本地(Mount the drive locally)。在文件中写入以下代码:
from google.colab import drive
drive.mount('/content/drive')
读取文件时的地址路径如下
(This screenshot is from the article “7 ways to load external data into Google Colab” B. Chen )
关于Evaluate Metrics
官方网站关于所有Metric的介绍:https://huggingface.co/evaluate-metric
有28种不同的矩阵, 下面贴上官方说明
>>>from datasets import list_metrics
>>>metrics_list = list_metrics()
>>>len(metrics_list)
>28
>>>print(metrics_list)
['accuracy', 'bertscore', 'bleu', 'bleurt', 'cer', 'comet', 'coval', 'cuad', 'f1', 'gleu', 'glue', 'indic_glue', 'matthews_correlation', 'meteor', 'pearsonr', 'precision', 'recall', 'rouge', 'sacrebleu', 'sari', 'seqeval', 'spearmanr', 'squad', 'squad_v2', 'super_glue', 'wer', 'wiki_split', 'xnli']
常见的使用组合:metric = load_metric("glue","mrpc")
同时显示accuracy和f1分数
如何在colab中加载python文件(saved on the google drive)
在加载google硬盘之后,!python 'filepath'
如何在 python文件中使用pip install
如果直接在python文件中写下pip install packagename 会跳出 Syntax Error。 因此改成导入pip包,使用pip包中内置的方法进行第三方库的下载。 解决方案参考帖子 Why does “pip install” inside Python raise a SyntaxError?
import pip
package_names=['datasets', 'transformers'] #packages to install
pip.main(['install'] + package_names + ['--upgrade'])
# --upgrade to install or update existing packages
Problem 1. Train loss is decreasing, but accuracy remain the same
Train_loss 不断下降但是accuracy没有变化
可能的原因:
- 过拟合。 可以尝试使用
weight_decayin theTrainingArguments,hidden_dropout_prob在model.from_pretrained(...)中设置和data augmentation解决. 参考帖子
边栏推荐
- ICC2使用report_placement检查floorplan
- DSX2-8000如何校准?校准流程?
- Pycharm2019设置编辑器主题和默认代码
- npm yarn相关的操作
- EXFO 730c optical time domain reflectometer only has IOLm optical eye to upgrade OTDR (open OTDR permission)
- Terminal resistance detailed signal complete series hardware learning notes 7
- set_ false_ path
- 低功耗设计-Power Switch
- Shuffle Net_ v1-shuffle_ v2
- What is the AEM testpro cv100 and fluke dsx-8000 of category 8 network cable tester?
猜你喜欢

What about the insufficient memory of Clickhouse aggregation? Then improve the polymerization performance

Analysis of MOSFET damage at the moment of power failure of isolated power supply

PLC的选型

mixup_ratio

Fluke dtx-sfm2 single mode module of a company in Hangzhou - repair case

PyTorch 学习笔记 4 —— 自动计算梯度下降 AUTOGRAD

Transformer 自注意力机制 及完整代码实现

Surge impact immunity experiment (surge) -emc series Hardware Design Notes 6

Learning notes of hardware circuit design 1 -- temperature rise design

vi和vim命令
随机推荐
Efficient Net_V2
Why should fluke dsx2-5000 network cable tester be calibrated once a year?
Esxi on arm 10/22 update
What is the AEM testpro cv100 and fluke dsx-8000 of category 8 network cable tester?
Perl入门学习(八)子程序
初学者进行传感器选型
clock tree分析实例
ICC2使用report_placement检查floorplan
mysql删表不删库
Low power design -power switch
CLIP Learning Transferable Visual Models From Natural Language Supervision
Create a basic report using MS chart controls
T-sne dimension reduction visualization
雷达成像 Matlab 仿真 1 —— LFM信号及其频谱
Terminal resistance detailed signal complete series hardware learning notes 7
Bag of tricks training convolution network skills
Efficient Net_ V2
Weight decay
Beta分布(概率的概率)
如何测试工业以太网线缆(利用FLUKE DSX-8000)?