File size: 1,163 Bytes
3be86d7
f0d5b9d
f4d4e26
875aaca
cd57423
 
f0d5b9d
cd57423
875aaca
 
cd57423
875aaca
 
 
 
 
 
 
7484466
875aaca
6553e18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3965872
a0ddc04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from transformers import pipeline
import streamlit as st

# Prog1: Classifier
# classifier = pipeline("sentiment-analysis")
# res = classifier("I have been waiting for the transformer my whole life")
# print(res)

# Prog2: Text Generator
# generator = pipeline("text-generation", model="distilgpt2")

# res = generator(
#     "In this course we will teach you how to",
#     max_length=100,
#     num_return_sequences=2,
# )
# st.write(res)

# Prog3: Zero Shot Classifier 

# classifier2 = pipeline("zero-shot-classification")
# res = classifier2(
#     "This is a course for Python List comprehension",
#     candidate_labels = ["education","politics","business"]
# )
# st.write(res)


# Prog4: Using Automodel and Autotokenizer

from transformers import AutoTokenizer, AutoModelForSequenceClassification

model_name = "distilbert-base-uncased-finetuned-sst-2-english"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

classifier3 = pipeline("sentiment-analysis",model=model,tokenizer=tokenizer)

res = classifier3("Newton has been the biggest physicist in modern times")
st.write(res)