Comments (5)
new_tokens=["443"]
model = "bert-base-chinese"
tokenizer = BertTokenizer.from_pretrained(model, use_fast=True)
model = BertForMaskedLM.from_pretrained(model)
num_added_toks = tokenizer.add_tokens(new_tokens)
model.resize_token_embeddings(len(tokenizer))
tokenizer.save_pretrained("bert-base-chinese")
执行上述代码回在模型下面生成 added_tokens.json文件。
训练时tcData.py文件
将tokenizer = PretrainedTokenizer.from_pretrained(config.pretrained_model_name_or_path)替换为
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained(config.pretrained_model_name_or_path)
或者手动添加方法
开始训练模型时都会报错。
from pytorch-nlu.
Traceback (most recent call last):
File "/home/pacs/PycharmProjects/untitled/myT/Pytorch-NLU_test.py", line 74, in
lc.train()
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/pytorch_nlu/pytorch_textclassification/tcRun.py", line 97, in train
self.office.train_model()
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/pytorch_nlu/pytorch_textclassification/tcOffice.py", line 215, in train_model
outputs = self.model(**inputs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/pytorch_nlu/pytorch_textclassification/tcGraph.py", line 63, in forward
output = self.model(input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/transformers/models/bert/modeling_bert.py", line 1020, in forward
encoder_outputs = self.encoder(
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/transformers/models/bert/modeling_bert.py", line 610, in forward
layer_outputs = layer_module(
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/transformers/models/bert/modeling_bert.py", line 495, in forward
self_attention_outputs = self.attention(
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/transformers/models/bert/modeling_bert.py", line 425, in forward
self_outputs = self.self(
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/transformers/models/bert/modeling_bert.py", line 284, in forward
mixed_query_layer = self.query(hidden_states)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/pacs/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/linear.py", line 114, in forward
return F.linear(input, self.weight, self.bias)
RuntimeError: CUDA error: CUBLAS_STATUS_NOT_INITIALIZED when calling cublasCreate(handle)
from pytorch-nlu.
复现但是没有出错呢,你这报错看着像是cuda的问题,比如版本不兼容pytorch
from pytorch-nlu.
找到原因了,我用pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Pytorch-NLU 安装的导致不是最新版代码。
from pytorch-nlu.
大佬,谢谢了帮忙排查问题。
from pytorch-nlu.
Related Issues (12)
- 请问当前代码中是否包含FLAT的相对位置矩阵处理? HOT 2
- 想问一下多标签是怎么处理的?跑多标签数据集的时候support值好像总和等于那些只有一个标签的 HOT 1
- 支持分类和实体识别联合训练吗?
- 请问怎么对复旦大学计算机信息与技术系国际数据库中心自然语言处理小组提供的新闻语料分类呢 HOT 1
- self.do_lower_case 和 self.vocab 没定义,执行报错?! HOT 2
- 支持英文吗 HOT 3
- 大佬跪求MiningZhiDaoQACorpus这个数据集求的共享链接,原链接失效了
- 大佬能不能出个零基础的傻瓜式训练测试教程啊,看着有点蒙。 HOT 3
- 请问读取数据集内存占用过高的问题 HOT 3
- 选择albert模型tokenizer加载错误
- 求回复:用bert-tiny做多标签分类,训练没有问题,保存了tc.config和tc.model,推理的时候在加载模型的地方报错 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch-nlu.