GithubHelp home page GithubHelp logo

Comments (4)

w5688414 avatar w5688414 commented on May 28, 2024

您是指的微调训练吗?微调可以取cls位置的向量作为句子级别的向量

from paddlenlp.

Alexander-jazz avatar Alexander-jazz commented on May 28, 2024

您是指的微调训练吗?微调可以取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.

w5688414 avatar w5688414 commented on May 28, 2024

最后一个一般是sep的token向量,不建议作为句子向量,建议还是cls位置,或者使用polled_output也行,polled_output一般是在token后面接入了linear层才输出的。

from paddlenlp.

Alexander-jazz avatar Alexander-jazz commented on May 28, 2024

最后一个一般是sep的token向量,不建议作为句子向量,建议还是cls位置,或者使用polled_output也行,polled_output一般是在token后面接入了linear层才输出的。

好的好的,十分感谢您!

from paddlenlp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.