当前位置:   article > 正文

在pipeline中使用distilbert-base-uncased-finetuned-sst-2-english模型做sentiment-analysis情感分析

distilbert-base-uncased-finetuned-sst-2-english

google colab 运行成功:

from transformers import AutoTokenizer, AutoModel,pipeline
from huggingface_hub.hf_api import HfFolder

HfFolder.save_token('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')
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer,MT5ForConditionalGeneration
checkpoint = "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModel.from_pretrained(checkpoint)
classifier = pipeline("sentiment-analysis", model=checkpoint,tokenizer=tokenizer)
print(classifier("I hate this"));
print(classifier(["I hate this","I love you"]));

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/347505
推荐阅读
相关标签
  

闽ICP备14008679号