Spaces:
Sleeping
Sleeping
#Python版本的transformers pipeline API | |
#https://huggingface.co/docs/transformers/main_classes/pipelines | |
#Java版本的transformers pipeline API | |
#https://huggingface.co/docs/transformers.js/pipelines#available-tasks | |
#Python版本示例:https://huggingface.co/docs/transformers/main_classes/pipelines | |
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer | |
# Sentiment analysis pipeline | |
analyzer = pipeline("sentiment-analysis") | |
#sentiment-analysis的default model是distilbert-base-uncased-finetuned-sst-2-english | |
#https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english?text=I+like+you.+I+love+you | |
#https://huggingface.co/blog/sentiment-analysis-python | |
# Question answering pipeline, specifying the checkpoint identifier | |
oracle = pipeline( | |
"question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="bert-base-cased" | |
) | |
# Named entity recognition pipeline, passing in a specific model and tokenizer | |
model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english") | |
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased") | |
recognizer = pipeline("ner", model=model, tokenizer=tokenizer) | |