| from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline |
| model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-base-turkish-sentiment-cased") |
| tokenizer = AutoTokenizer.from_pretrained("savasy/bert-base-turkish-sentiment-cased") |
| sa= pipeline("sentiment-analysis", tokenizer=tokenizer, model=model) |
|
|
| def adjust(x): |
| if x<0: |
| return 2*x+1 |
| return 2*x-1 |
|
|
| def sa2(s): |
| res= sa(s) |
| return [adjust(-1*r['score']) if r['label']=='negative' else adjust(r['score']) for r in res ] |
| |
| |
| def get_examples(): |
| |
| return ["Bu filmi beğenmedim\n bu filmi beğendim\n ceketin çok güzel\n bugün ne yesek"] |
|
|
| import pandas as pd |
|
|
| import matplotlib.pyplot as plt |
| def grfunc(comments): |
| df=pd.DataFrame() |
| c2=[s.strip() for s in comments.split("\n") if len(s.split())>2] |
| df["scores"]= sa2(c2) |
| df.plot(kind='hist') |
| return plt.gcf() |
| |
| import gradio as gr |
|
|
| iface = gr.Interface( |
| fn=grfunc, |
| inputs=gr.inputs.Textbox(placeholder="put your sentences line by line", lines=5), |
| outputs="plot", |
| examples=get_examples()) |
| iface.launch() |
|
|