Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,8 @@ from transformers import AutoTokenizer, AutoModelForMaskedLM, AutoModelForSeq2Se
|
|
5 |
BERTTokenizer = AutoTokenizer.from_pretrained("cl-tohoku/bert-base-japanese")
|
6 |
BERTModel = AutoModelForMaskedLM.from_pretrained("cl-tohoku/bert-base-japanese")
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
GPT2Tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt2-medium")
|
12 |
GPT2Model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt2-medium")
|
@@ -37,23 +37,23 @@ def BALTHASAR(sue):#mT5
|
|
37 |
votes.append(1 if probs[-1][allow]>probs[-1][deny] else -1)
|
38 |
return "承認" if probs[-1][allow]>probs[-1][deny] else "否定"
|
39 |
|
40 |
-
def
|
41 |
-
allow=
|
42 |
-
deny=
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
return "承認" if probs[i][allow]>probs[i][deny] else "否定"
|
50 |
|
51 |
def greet(sue):
|
52 |
text1="BERT-1"+MELCHIOR(sue)
|
53 |
text2="GPT-2"+CASPER(sue)
|
54 |
-
text3="
|
55 |
return text1+" "+text2+" "+text3+"\n___\n\n"+("|可決|" if sum(votes[-3:])>0 else "| 否決 |")+"\n___"
|
56 |
|
|
|
57 |
css="@import url('https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@800&display=swap'); .gradio-container {background-color: black} .gr-button {background-color: blue;color:black; weight:200%;font-family:'Shippori Mincho', serif;}"
|
58 |
css+=".block{color:orange;} ::placeholder {font-size:35%} .gr-box {text-align: center;font-size: 125%;border-color:orange;background-color: #000000;weight:200%;font-family:'Shippori Mincho', serif;}:disabled {color: orange;opacity:1.0;}"
|
59 |
with gr.Blocks(css=css) as demo:
|
|
|
5 |
BERTTokenizer = AutoTokenizer.from_pretrained("cl-tohoku/bert-base-japanese")
|
6 |
BERTModel = AutoModelForMaskedLM.from_pretrained("cl-tohoku/bert-base-japanese")
|
7 |
|
8 |
+
mBERTTokenizer = AutoTokenizer.from_pretrained("bert-base-multilingual-cased")
|
9 |
+
mBERTModel = AutoModelForMaskedLM.from_pretrained("bert-base-multilingual-cased")
|
10 |
|
11 |
GPT2Tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt2-medium")
|
12 |
GPT2Model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt2-medium")
|
|
|
37 |
votes.append(1 if probs[-1][allow]>probs[-1][deny] else -1)
|
38 |
return "承認" if probs[-1][allow]>probs[-1][deny] else "否定"
|
39 |
|
40 |
+
def BALTHASAR(sue):#mBERT
|
41 |
+
allow=mBERTTokenizer("Yes").input_ids[1]
|
42 |
+
deny=mBERTTokenizer("No").input_ids[1]
|
43 |
+
output=mBERTModel(**mBERTTokenizer('MELCHIORは科学者としての人格を持っています。人間とMELCHIORの対話です。人間「'+sue+'。賛成か反対か。」'+"MELCHIOR 「[MASK]」",return_tensors="pt")).logits
|
44 |
+
mask=output[0,-3,:]
|
45 |
+
print(mBERTTokenizer.decode(torch.argmax(output[0,-3,:])))
|
46 |
+
votes.append(1 if mask[allow]>mask[deny] else -1)
|
47 |
+
return "承認" if mask[allow]>mask[deny] else "否定"
|
48 |
+
|
|
|
49 |
|
50 |
def greet(sue):
|
51 |
text1="BERT-1"+MELCHIOR(sue)
|
52 |
text2="GPT-2"+CASPER(sue)
|
53 |
+
text3="mBERT-3"+BALTHASAR(sue)
|
54 |
return text1+" "+text2+" "+text3+"\n___\n\n"+("|可決|" if sum(votes[-3:])>0 else "| 否決 |")+"\n___"
|
55 |
|
56 |
+
|
57 |
css="@import url('https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@800&display=swap'); .gradio-container {background-color: black} .gr-button {background-color: blue;color:black; weight:200%;font-family:'Shippori Mincho', serif;}"
|
58 |
css+=".block{color:orange;} ::placeholder {font-size:35%} .gr-box {text-align: center;font-size: 125%;border-color:orange;background-color: #000000;weight:200%;font-family:'Shippori Mincho', serif;}:disabled {color: orange;opacity:1.0;}"
|
59 |
with gr.Blocks(css=css) as demo:
|