aino-capm commited on
Commit
6e757a0
1 Parent(s): 371b54a
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import BertJapaneseTokenizer, BertForSequenceClassification
4
+
5
+ # 日本語の事前学習モデル
6
+ MODEL_NAME = 'cl-tohoku/bert-base-japanese-whole-word-masking'
7
+ descriptions = '''BERTをchABSA-datasetでファインチューニングしたもの。
8
+ chABSA-datasetは上場企業の有価証券報告書をベースに作成されたネガポジ用データセット'''
9
+
10
+ tokenizer = BertJapaneseTokenizer.from_pretrained(MODEL_NAME)
11
+ bert_sc_ = BertForSequenceClassification.from_pretrained("models/")
12
+ bert_sc = bert_sc_.to("cpu")
13
+
14
+ def func(text):
15
+ encoding = tokenizer(
16
+ text,
17
+ padding = "longest",
18
+ return_tensors="pt"
19
+ )
20
+ encoding = { k : v.cpu() for k, v in encoding.items()}
21
+
22
+ with torch.no_grad():
23
+ output = bert_sc(**encoding)
24
+ scores = output.logits.argmax(-1)
25
+
26
+ label = "ネガティブ" if scores.item()==0 else "ポジティブ"
27
+
28
+ return label,text
29
+
30
+ app = gr.Interface(fn=func, inputs="text", outputs=["label","text"], title="ビジネス文書/ネガポジ分析", description=descriptions)
31
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ transformers==4.20.0
3
+ sentencepiece