Spaces:
Sleeping
Sleeping
File size: 7,512 Bytes
40d1f52 9bbdcc4 a7187dd 84f8a6c 40d1f52 9bbdcc4 bc51159 9bbdcc4 ba9b1bc 40d1f52 be274f0 5a493cf debbb1a 9110242 efb1390 70370ca 66e1140 74ad74c ba9b1bc 40d1f52 ba9b1bc 40d1f52 70370ca 40d1f52 bc51159 70a7d42 bc51159 4c2e53d 70a7d42 4c2e53d 40d1f52 bc51159 66e1140 70370ca 66e1140 bc51159 40d1f52 84f8a6c f17857a 84f8a6c 40d1f52 84f8a6c 45bb40c 40d1f52 84f8a6c 0f567c2 84f8a6c 0f567c2 84f8a6c bc51159 84f8a6c 5d70280 217b6cf 45bb40c f17857a 45bb40c 40d1f52 5d70280 bb0c7d4 4c2e53d a86e9de 84f8a6c a86e9de |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
import gradio as gr
import pandas as pd
from graph_utils import *
from transformers import pipeline
languages = pd.read_csv("model_lang.csv", names=["Lang_acr"])
def check_lang(lang_acronym):
if lang_acronym in languages["Lang_acr"].to_list():
return "True"
else:
return "False"
title = "DReAM"
description_main = """
This space allows you to test a set of LLMs tuned to perform different tasks over dream reports.
Three main tasks are available:
- Name Entity Recognition (NER), with an English-only model that generates the identified characters.
- Sentiment Analysis (SA), with two English-only models (one for multi-label classification, and one for generation) and a large multilingual model for multi-label classification.
- Relation Extraction (RE), with an English-only model that identifies relevant characters and existing relations between them following the Activity feature of the Hall and Van de Castle framework.
All models have been tuned on the Hall and Van de Castle framework. More details are on the page for each model. For more techincal and theoretical details, see the [Bertolini et al., 2024](https://aclanthology.org/2024.clpsych-1.7/), and [Bertolini et al., 2024](https://www.sciencedirect.com/science/article/pii/S1389945723015186?via%3Dihub).
Use the current interface to check if a language is included in the multilingual SA model, using language acronyms (e.g. it for Italian). the tabs above will direct you to each model to query.
If you want to use the models outside the space, you can easily do so via [DReAMy](https://github.com/lorenzoscottb/DReAMy)
"""
description_L = """
This model is an XLM-R tuned model, pre-trained with 94 languages available, and tuned on emotion-annotated DreamBank English data. (see original model [card](https://huggingface.co/xlm-roberta-large) to see which are available)
"""
description_S = """
A BERT-base-cased model pre-trained on English-only text and tuned on annotated DreamBank English data.
"""
description_G = """
A T5 model tuned to perform text generation and predict emotion as well as the character experiencing those emotions.
"""
description_R = """
A T5 model tuned to perform text generation and predicts the characters and the (activity) relation between them.
"""
description_GNER = """
A T5 model tuned to perform text generation, and predict which characters are present in the report. Note that, in the Hall and Van de Castle, the character lists never includes the dreamer. Hence, if you (willingly or not) enter a report that does not contain another character reference, the model will/should (correctly) produce an empty string. Moreover, it is likely that the produced list of CHAR could be longer than the one produced by the SA model, as not all CHAR might be associated with emotions.
"""
examples = [
["I was followed by the blue monster but was not scared. I was calm and relaxed."],
["Ero seguito dal mostro blu, ma non ero spaventato. Ero calmo e rilassato."],
["Śledził mnie niebieski potwór, ale się nie bałem. Byłem spokojny i zrelaksowany."],
]
examples_g = [
["I'm in an auditorium. Susie S is concerned at her part in this disability awareness spoof we are preparing. I ask, 'Why not do it? Lots of AB's represent us in a patronizing way. Why shouldn't we represent ourselves in a good, funny way?' I watch the video we all made. It is funny. I try to sit on a folding chair. Some guy in front talks to me. Merle is in the audience somewhere. [BL]"],
]
examples_re = [
["I was skating on the outdoor ice pond that used to be across the street from my house. I was not alone, but I did not recognize any of the other people who were skating around. I went through my whole repertoire of jumps, spires, and steps-some of which I can do and some of which I'm not yet sure of. They were all executed flawlessly-some I repeated, some I did only once. I seemed to know that if I went into competition, I would be sure of coming in third because there were only three contestants. Up to that time I hadn't considered it because I hadn't thought I was good enough, but now since everything was going so well, I decided to enter."],
["I was talking on the telephone to the father of an old friend of mine (boy, 21 years old). We were discussing the party the Saturday night before to which I had invited his son as a guest. I asked him if his son had a good time at the party. He told me not to tell his son that he had told me, but that he had had a good time, except he was a little surprised that I had acted the way I did."],
["I was walking alone with my dog in a forest."]
]
interface_words = gr.Interface(
fn=check_lang,
inputs="text",
outputs="text",
title=title,
description=description_main,
examples=["en", "it", "pl"],
cache_examples=True,
)
# interface_model_L = gr.Interface(
# description=description_L,
# examples=examples,
# title="SA Large Multilingual",
# )
# interface_model_L.load("models/DReAMy-lib/xlm-roberta-large-DreamBank-emotion-presence")
pipe_S = pipeline("text2text-generation", model="DReAMy-lib/t5-base-DreamBank-Generation-Emot-Char")
def predict(text):
return pipe_S(text)
interface_model_S = gr.Interface(
fn=pipe_S,
inputs='text',
outputs='label',
examples=examples[0],
title="SA Base English-Only",
description=description_S,
cache_examples=True,
)
# interface_model_G = gr.Interface.load(
# "models/DReAMy-lib/t5-base-DreamBank-Generation-Emot-Char",
# examples=examples_g,
# title="SA Generation",
# )
interface_model_RE = gr.Interface(
text_to_graph,
inputs=gr.Textbox(label="Text", placeholder="Enter a text here."),
outputs=[gr.HTML(label="Extracted graph"),gr.Textbox(label="Extracted text")],
examples= [
"I was skating on the outdoor ice pond that used to be across the street from my house. I was not alone, but I did not recognize any of the other people who were skating around. I went through my whole repertoire of jumps, spires, and steps-some of which I can do and some of which I'm not yet sure of. They were all executed flawlessly-some I repeated, some I did only once. I seemed to know that if I went into competition, I would be sure of coming in third because there were only three contestants. Up to that time I hadn't considered it because I hadn't thought I was good enough, but now since everything was going so well, I decided to enter.",
"I was talking on the telephone to the father of an old friend of mine (boy, 21 years old). We were discussing the party the Saturday night before to which I had invited his son as a guest. I asked him if his son had a good time at the party. He told me not to tell his son that he had told me, but that he had had a good time, except he was a little surprised that I had acted the way I did.",
"I was walking alone with my dog in a forest."
],
title=title,
description=description_R,
cache_examples=True,
)
# interface_model_NER = gr.Interface.load(
# "models/DReAMy-lib/t5-base-DreamBank-Generation-NER-Char",
# examples=examples_g,
# title="NER Generation",
# )
gr.TabbedInterface(
[interface_words, interface_model_S, interface_model_RE],
["Main", "SA English", "RE"],
).launch()
|