iShare commited on
Commit
7632f13
1 Parent(s): 2122b62

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Python版本的transformers pipeline API
2
+ #https://huggingface.co/docs/transformers/main_classes/pipelines
3
+
4
+ #Java版本的transformers pipeline API
5
+ #https://huggingface.co/docs/transformers.js/pipelines#available-tasks
6
+
7
+ #Python版本示例:https://huggingface.co/docs/transformers/main_classes/pipelines
8
+ from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
9
+
10
+ # Sentiment analysis pipeline
11
+ analyzer = pipeline("sentiment-analysis")
12
+ #sentiment-analysis的default model是distilbert-base-uncased-finetuned-sst-2-english
13
+ #https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english?text=I+like+you.+I+love+you
14
+ #https://huggingface.co/blog/sentiment-analysis-python
15
+
16
+ # Question answering pipeline, specifying the checkpoint identifier
17
+ oracle = pipeline(
18
+ "question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="bert-base-cased"
19
+ )
20
+
21
+ # Named entity recognition pipeline, passing in a specific model and tokenizer
22
+ model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english")
23
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
24
+ recognizer = pipeline("ner", model=model, tokenizer=tokenizer)
25
+