Dmitry Kirsanov commited on
Commit
2faa652
·
1 Parent(s): b72e4e6

first try at annotation

Browse files
Files changed (2) hide show
  1. app.py +2 -1
  2. understand.py +37 -1
app.py CHANGED
@@ -25,7 +25,8 @@ gradio_app = gr.Interface(
25
  gr.Textbox(label="Summary", lines=8),
26
  gr.Textbox(label="Concepts", lines=10),
27
  gr.Textbox(label="Actors", lines=10),
28
- gr.Textbox(label="Actors, generalized", lines=10)
 
29
  ]
30
  )
31
 
 
25
  gr.Textbox(label="Summary", lines=8),
26
  gr.Textbox(label="Concepts", lines=10),
27
  gr.Textbox(label="Actors", lines=10),
28
+ gr.Textbox(label="Actors, generalized", lines=10),
29
+ gr.Textbox(label="Document, annotated with actors", lines=18),
30
  ]
31
  )
32
 
understand.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import parse
2
  import llm
3
  from versioneddict import VersionedDict
@@ -79,8 +81,11 @@ Give a one-paragraph summary of the document's content. Write just one paragraph
79
 
80
  print(f"===Parsed list {what}: {retlist}")
81
  return retlist
 
82
 
83
-
 
 
84
  def query_concepts(self):
85
  two_attempts = [{"actors": [], "concepts": []}, {"actors": [], "concepts": []}]
86
 
@@ -183,6 +188,35 @@ Output the line "ACTORS:" followed by your list of actors, one per line.
183
  generalized = self.parse_lists(ret, "actors")
184
  self.values.put("actors, generalized", generalized)
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  def ingest(self, filename):
187
  soup = parse.parse(filename)
188
  self.values.put("document (soup)", soup)
@@ -197,6 +231,7 @@ Output the line "ACTORS:" followed by your list of actors, one per line.
197
  if self.values.is_newer("FAD", "concepts"):
198
  self.query_concepts()
199
  self.generalize_actors()
 
200
 
201
  def get_understanding(self):
202
  self.understand()
@@ -205,6 +240,7 @@ Output the line "ACTORS:" followed by your list of actors, one per line.
205
  "=== Concepts:\n"+newline.join(["- " + x for x in self.values.get("concepts")]),
206
  "=== Actors:\n"+newline.join(["- " + x for x in self.values.get("actors")]),
207
  "=== Actors, generalized:\n"+newline.join(["- " + x for x in self.values.get("actors, generalized")]),
 
208
  )
209
 
210
 
 
1
+ import re
2
+
3
  import parse
4
  import llm
5
  from versioneddict import VersionedDict
 
81
 
82
  print(f"===Parsed list {what}: {retlist}")
83
  return retlist
84
+
85
 
86
+ def parse_document(self, ret):
87
+ return re.sub(r'^<document>(.*)</document>$', r'\1', ret, flags=re.DOTALL)
88
+
89
  def query_concepts(self):
90
  two_attempts = [{"actors": [], "concepts": []}, {"actors": [], "concepts": []}]
91
 
 
188
  generalized = self.parse_lists(ret, "actors")
189
  self.values.put("actors, generalized", generalized)
190
 
191
+
192
+ def annotate_actors(self):
193
+ ret = self.query(
194
+ f"""Below is a document inside <document></document>. It is a {self.values.get("document type")}.
195
+
196
+ Summary of the document:
197
+ {self.values.get("summary")}
198
+
199
+ Read the entire document carefully. Remember everything you know about the concepts it touches.
200
+
201
+ A reader of this document has compiled a list of actors (parties) mentioned or implied in the document. Here is their list:
202
+
203
+ {newline.join(["- " + x for x in self.values.get("actors")])}
204
+
205
+ Your goal is to annotate each sentence of this document with its intended audience, by picking parties from this list. For each sentence, ask yourself: which of the parties from the list would benefit from this sentence's information? Add the relevant partes, separated by commas, after the end of the sentence in [[double brackets]].
206
+
207
+ For example, imagine you have a document describing the process of submitting a scientific paper for publication, and your parties are "Authors" and "Publishers". Here are example sentences with audience markup:
208
+
209
+ Format the references in your paper according to journal guidelines..[[Authors]]
210
+ Ensure the papers submitted through the online platform are indexed in relevant databases and repositories.[[Publishers]]
211
+ The journey of the manuscript begins with an initial editorial review conducted by journal editors.[[Authors,Publishers]]
212
+
213
+ Output just the document with the audience markup after each sentence, but otherwise unchanged.
214
+
215
+ <document>{self.values.get("FAD")}</document>""")
216
+ annotated = self.parse_document(ret)
217
+ self.values.put("FAD with actors", annotated)
218
+
219
+
220
  def ingest(self, filename):
221
  soup = parse.parse(filename)
222
  self.values.put("document (soup)", soup)
 
231
  if self.values.is_newer("FAD", "concepts"):
232
  self.query_concepts()
233
  self.generalize_actors()
234
+ self.annotate_actors()
235
 
236
  def get_understanding(self):
237
  self.understand()
 
240
  "=== Concepts:\n"+newline.join(["- " + x for x in self.values.get("concepts")]),
241
  "=== Actors:\n"+newline.join(["- " + x for x in self.values.get("actors")]),
242
  "=== Actors, generalized:\n"+newline.join(["- " + x for x in self.values.get("actors, generalized")]),
243
+ "=== Document annotated:\n"+self.values.get("FAD with actors")
244
  )
245
 
246