ArneBinder commited on
Commit
f3e17f7
1 Parent(s): 02c4172

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +56 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pie_modules.models import * # noqa: F403
3
+ from pie_modules.taskmodules import * # noqa: F403
4
+ from prettytable import PrettyTable
5
+ from pytorch_ie.annotations import LabeledSpan
6
+ from pytorch_ie.auto import AutoPipeline
7
+ from pytorch_ie.documents import TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
8
+ from pytorch_ie.models import * # noqa: F403
9
+ from pytorch_ie.taskmodules import * # noqa: F403
10
+
11
+
12
+ def predict(text):
13
+ document = TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions(text=text)
14
+
15
+ # add single partition from the whole text (the model only considers text in partitions)
16
+ document.labeled_partitions.append(LabeledSpan(start=0, end=len(text), label="text"))
17
+
18
+ # execute NER pipeline
19
+ pipeline(document)
20
+
21
+ t = PrettyTable()
22
+ t.field_names = ["head", "tail", "relation"]
23
+ t.align = "l"
24
+ for relation in document.binary_relations.predictions:
25
+ t.add_row([str(relation.head), str(relation.tail), relation.label])
26
+
27
+ html = t.get_html_string(format=True)
28
+ html = "<div style='max-width:100%; max-height:360px; overflow:auto'>" + html + "</div>"
29
+
30
+ return html
31
+
32
+
33
+ if __name__ == "__main__":
34
+
35
+ model_name_or_path = "ArneBinder/sam-pointer-bart-base-v0.3"
36
+ # model_name_or_path = "models/dataset-sciarg/task-ner_re/v0.3/2024-03-01_18-25-32"
37
+
38
+ pipeline = AutoPipeline.from_pretrained(model_name_or_path, device=-1, num_workers=0)
39
+ re_pipeline = AutoPipeline.from_pretrained(
40
+ model_name_or_path,
41
+ device=-1,
42
+ num_workers=0,
43
+ # taskmodule_kwargs=dict(create_relation_candidates=True),
44
+ )
45
+
46
+ iface = gr.Interface(
47
+ fn=predict,
48
+ inputs=[
49
+ gr.Textbox(
50
+ lines=20,
51
+ value="Scholarly Argumentation Mining (SAM) has recently gained attention due to its potential to help scholars with the rapid growth of published scientific literature. It comprises two subtasks: argumentative discourse unit recognition (ADUR) and argumentative relation extraction (ARE), both of which are challenging since they require e.g. the integration of domain knowledge, the detection of implicit statements, and the disambiguation of argument structure. While previous work focused on dataset construction and baseline methods for specific document sections, such as abstract or results, full-text scholarly argumentation mining has seen little progress. In this work, we introduce a sequential pipeline model combining ADUR and ARE for full-text SAM, and provide a first analysis of the performance of pretrained language models (PLMs) on both subtasks. We establish a new SotA for ADUR on the Sci-Arg corpus, outperforming the previous best reported result by a large margin (+7% F1). We also present the first results for ARE, and thus for the full AM pipeline, on this benchmark dataset. Our detailed error analysis reveals that non-contiguous ADUs as well as the interpretation of discourse connectors pose major challenges and that data annotation needs to be more consistent.",
52
+ )
53
+ ],
54
+ outputs=["html"],
55
+ )
56
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers==4.36.0
2
+ gradio==4.31.4
3
+ prettytable==3.10.0
4
+ pie-modules>=0.10.9,<0.11.0