Dmitry Kirsanov commited on
Commit
b72e4e6
·
1 Parent(s): 34e4e55

generalize lists

Browse files
Files changed (2) hide show
  1. app.py +8 -1
  2. understand.py +33 -0
app.py CHANGED
@@ -20,7 +20,14 @@ gradio_app = gr.Interface(
20
  fn=process,
21
  allow_flagging="auto",
22
  inputs=[gr.File(label="Input document (HTML)"), gr.Dropdown(choices=LLM.get_models(), value=LLM.get_models()[0])],
23
- outputs=[gr.Textbox(label="Document type", lines=1), gr.Textbox(label="Summary", lines=8), gr.Textbox(label="Concepts", lines=10), gr.Textbox(label="Actors", lines=10)])
 
 
 
 
 
 
 
24
 
25
  if __name__ == "__main__":
26
  logger.info("DU starts!")
 
20
  fn=process,
21
  allow_flagging="auto",
22
  inputs=[gr.File(label="Input document (HTML)"), gr.Dropdown(choices=LLM.get_models(), value=LLM.get_models()[0])],
23
+ outputs=[
24
+ gr.Textbox(label="Document type", lines=1),
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
 
32
  if __name__ == "__main__":
33
  logger.info("DU starts!")
understand.py CHANGED
@@ -4,6 +4,16 @@ from versioneddict import VersionedDict
4
 
5
  newline = "\n"
6
 
 
 
 
 
 
 
 
 
 
 
7
  class Document():
8
 
9
  def __init__(self, llm) -> None:
@@ -152,6 +162,27 @@ Here's the document:
152
  print(f"===Reconciled: Concepts: {self.values.get('concepts')}, Actors: {self.values.get('actors')}")
153
 
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  def ingest(self, filename):
156
  soup = parse.parse(filename)
157
  self.values.put("document (soup)", soup)
@@ -165,6 +196,7 @@ Here's the document:
165
  self.query_summary()
166
  if self.values.is_newer("FAD", "concepts"):
167
  self.query_concepts()
 
168
 
169
  def get_understanding(self):
170
  self.understand()
@@ -172,6 +204,7 @@ Here's the document:
172
  return (self.values.get("document type"), self.values.get("summary"),
173
  "=== Concepts:\n"+newline.join(["- " + x for x in self.values.get("concepts")]),
174
  "=== Actors:\n"+newline.join(["- " + x for x in self.values.get("actors")]),
 
175
  )
176
 
177
 
 
4
 
5
  newline = "\n"
6
 
7
+
8
+ # TODO: move all understandings to this class; make values a list of instances of understanding
9
+ class Understanding():
10
+
11
+ def __init__(self) -> None:
12
+ self.query = None
13
+ self.present = None
14
+ self.key = ""
15
+
16
+
17
  class Document():
18
 
19
  def __init__(self, llm) -> None:
 
162
  print(f"===Reconciled: Concepts: {self.values.get('concepts')}, Actors: {self.values.get('actors')}")
163
 
164
 
165
+ def generalize_actors(self):
166
+ ret = self.query(
167
+ f"""Below is a document inside <document></document>. It is a {self.values.get("document type")}.
168
+
169
+ Summary of the document:
170
+ {self.values.get("summary")}
171
+
172
+ Read the entire document carefully. Remember everything you know about the concepts it touches.
173
+
174
+ A reader of this document has compiled a list of actors mentioned or implied in the document. Here is their list:
175
+
176
+ {newline.join(["- " + x for x in self.values.get("actors")])}
177
+
178
+ Your goal is to generalize this list, replacing groups of actors playing the same or similar roles with their generic term. If an actor is not very relevant to the document (that is, you cannot see this document as written by, for, or about this actor), then drop it altogether. Try to pare this list down as much as possible, leaving only the most important categories of actors.
179
+
180
+ Output the line "ACTORS:" followed by your list of actors, one per line.
181
+
182
+ <document>{self.values.get("FAD")}</document>""")
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)
 
196
  self.query_summary()
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()
 
204
  return (self.values.get("document type"), self.values.get("summary"),
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