Comments (4)
您是指的微调训练吗?微调可以取cls位置的向量作为句子级别的向量
from paddlenlp.
您是指的微调训练吗?微调可以取cls位置的向量作为句子级别的向量
您好,我没有微调训练,是直接用你们训练好的模型的,模型名称为“ernie-health-chinese”。代码如下:
from paddlenlp.transformers import * tokenizer = AutoTokenizer.from_pretrained('ernie-health-chinese') ernie = AutoModel.from_pretrained('ernie-health-chinese') text = tokenizer('心跳加速') emb = ernie(input_ids=paddle.to_tensor([text['input_ids']])) print(emb.shape)
运行结果如下:
D:\Anaconda3\envs\OHCDoctorKnowledge\lib\site-packages\_distutils_hack\__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") [2024-05-03 09:47:46,101] [ INFO] - We are using <class 'paddlenlp.transformers.electra.tokenizer.ElectraTokenizer'> to load 'ernie-health-chinese'. [2024-05-03 09:47:46,101] [ INFO] - Already cached C:\Users\Evans\.paddlenlp\models\ernie-health-chinese\vocab.txt [2024-05-03 09:47:46,116] [ INFO] - tokenizer config file saved in C:\Users\Evans\.paddlenlp\models\ernie-health-chinese\tokenizer_config.json [2024-05-03 09:47:46,116] [ INFO] - Special tokens file saved in C:\Users\Evans\.paddlenlp\models\ernie-health-chinese\special_tokens_map.json [2024-05-03 09:47:46,116] [ INFO] - We are using <class 'paddlenlp.transformers.electra.modeling.ElectraModel'> to load 'ernie-health-chinese'. [2024-05-03 09:47:46,116] [ INFO] - Already cached C:\Users\Evans\.paddlenlp\models\ernie-health-chinese\ernie-health-chinese.pdparams W0503 09:47:46.116991 23592 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 12.0, Runtime API Version: 11.7 W0503 09:47:46.116991 23592 gpu_resources.cc:91] device: 0, cuDNN Version: 8.5. [1, 6, 768]
可以发现,输出的形状是按照字输出的,如果直接用你们训练好的这个模型,也可以用最后一个字的输出作为整个句子的语义表示吗?另外,我试了一下"ernie-3.0-medium-zh"模型,这个输出是两个tensor,第一个是按字的sequence_output输出[1,字数+2,768],另一个是[1,768]的pooled_output整句输出,按字的输出最后一个字的向量和pooled_output是不一样的。我是深度学习小白,给您添麻烦了,感谢!
from paddlenlp.
最后一个一般是sep的token向量,不建议作为句子向量,建议还是cls位置,或者使用polled_output也行,polled_output一般是在token后面接入了linear层才输出的。
from paddlenlp.
最后一个一般是sep的token向量,不建议作为句子向量,建议还是cls位置,或者使用polled_output也行,polled_output一般是在token后面接入了linear层才输出的。
好的好的,十分感谢您!
from paddlenlp.
Related Issues (20)
- [Question]: 使用develop版本的paddlepaddle cpu 版本执行retrieval_based的export_to_serving报错 HOT 1
- [Question]: NPU下支持的功能有哪些 HOT 1
- [Question]: 进行实体抽取时,能否获得各个schema的bbox HOT 1
- [Question]: paddleNLP-uie 是否可以在移动端上使用 HOT 1
- [Question]: pipelines的faiss如何根据条件删除向量 HOT 1
- Taskflow默认的最大序列长度怎么看?FastDeploy UIE中最长序列长度怎么设置? HOT 12
- [Question]: 2.8版本使用LLM工作流报错缺少fused_ln HOT 2
- [Bug]: pipelines中语义检索系统,启动运行后,上传扫描式PDF文件 无法解析 HOT 1
- [Bug]: TaskFlow zero_shot_text_classification HOT 3
- [Bug]: get_rank_by_dim_and_process_id 函数未实现
- [Question]: paddle.distributed.launch 启动多进程训练结束后Loading best model from checkpoint 报错 HOT 7
- 如何对长文本进行抽取 HOT 3
- uie可以做嵌套抽取吗? HOT 3
- 文档公式有误 HOT 5
- [Question]: 请问文档智能任务有用自己数据集微调的教程吗? HOT 1
- [Bug]: ImportError: DLL load failed while importing libpaddle: 找不到指定的程序。
- [Question]: 分布式
- [Question]: Data annotation and pre processing for Relation Extraction
- [Bug]: paddle的nansum不支持empty的求和
- [Bug]: Taskflow("document_intelligence"): Illegal instruction (core dumped) HOT 7
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 paddlenlp.