abdiharyadi commited on
Commit
1556875
β€’
1 Parent(s): 35d002b

feat: integrate AMRToText and reactivate TextToAMR

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -16,6 +16,7 @@ sys.path.append("./amr-tst-indo")
16
  from text_to_amr import TextToAMR
17
  from style_detector import StyleDetector
18
  from style_rewriting import StyleRewriting
 
19
 
20
  amr_parsing_model_name = "mbart-en-id-smaller-indo-amr-parsing-translated-nafkhan"
21
  snapshot_download(
@@ -56,6 +57,20 @@ sr = StyleRewriting(
56
  maximize_style_words_expansion=False
57
  )
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  def run(text, source_style):
60
  yield (
61
  "(Memproses ...)",
@@ -67,15 +82,7 @@ def run(text, source_style):
67
 
68
  start_time = time.time()
69
 
70
- # source_amr, *_ = t2a([text])
71
- source_amr = penman.decode("""
72
- (z0 / dan
73
- :op1 (z1 / bagus-01
74
- :ARG1 (z2 / tempat)
75
- :degree (z3 / sangat))
76
- :op2 (z4 / bersih-01
77
- :ARG1 z2))
78
- """)
79
  source_amr.metadata = {}
80
  source_amr_display = penman.encode(source_amr)
81
  source_amr_display += f"\n\n({time.time() - start_time:.2f} s)"
@@ -88,10 +95,6 @@ def run(text, source_style):
88
  )
89
 
90
  triplets = sd.get_triplets(text)
91
- # triplets = [
92
- # ("kamar", "sangat bagus", "positif"),
93
- # ("kamar", "bersih", "positif")
94
- # ]
95
  triplets_display = "\n".join(f"({x[0]}, {x[1]}, {x[2]})" for x in triplets)
96
  triplets_display += f"\n\n({time.time() - start_time:.2f} s)"
97
  yield (
@@ -103,7 +106,6 @@ def run(text, source_style):
103
  )
104
 
105
  style_words = sd.get_style_words_from_triplets(triplets)
106
- # style_words = ["bagus", "bersih"]
107
  style_words_display = ", ".join(style_words)
108
  style_words_display += f"\n\n({time.time() - start_time:.2f} s)"
109
  yield (
@@ -125,7 +127,7 @@ def run(text, source_style):
125
  "(Memproses ...)",
126
  )
127
 
128
- result = f"dunia ({text=}, {source_style=})"
129
  result += f"\n\n({time.time() - start_time:.2f} s)"
130
  yield (
131
  source_amr_display,
 
16
  from text_to_amr import TextToAMR
17
  from style_detector import StyleDetector
18
  from style_rewriting import StyleRewriting
19
+ from amr_to_text import AMRToTextWithTaufiqMethod
20
 
21
  amr_parsing_model_name = "mbart-en-id-smaller-indo-amr-parsing-translated-nafkhan"
22
  snapshot_download(
 
57
  maximize_style_words_expansion=False
58
  )
59
 
60
+ amr_gen_model_name = "taufiq-indo-amr-generation-gold-uncased"
61
+ model_path = f"./{amr_gen_model_name}"
62
+ snapshot_download(
63
+ repo_id=f"abdiharyadi/{amr_gen_model_name}",
64
+ local_dir=model_path,
65
+ allow_patterns=[
66
+ "*checkpoint-3*"
67
+ ]
68
+ )
69
+ a2t = AMRToTextWithTaufiqMethod(
70
+ model_path=os.path.join(model_path, "checkpoint-3"),
71
+ lowercase=True,
72
+ )
73
+
74
  def run(text, source_style):
75
  yield (
76
  "(Memproses ...)",
 
82
 
83
  start_time = time.time()
84
 
85
+ source_amr, *_ = t2a([text])
 
 
 
 
 
 
 
 
86
  source_amr.metadata = {}
87
  source_amr_display = penman.encode(source_amr)
88
  source_amr_display += f"\n\n({time.time() - start_time:.2f} s)"
 
95
  )
96
 
97
  triplets = sd.get_triplets(text)
 
 
 
 
98
  triplets_display = "\n".join(f"({x[0]}, {x[1]}, {x[2]})" for x in triplets)
99
  triplets_display += f"\n\n({time.time() - start_time:.2f} s)"
100
  yield (
 
106
  )
107
 
108
  style_words = sd.get_style_words_from_triplets(triplets)
 
109
  style_words_display = ", ".join(style_words)
110
  style_words_display += f"\n\n({time.time() - start_time:.2f} s)"
111
  yield (
 
127
  "(Memproses ...)",
128
  )
129
 
130
+ result, *_ = a2t([target_amr])
131
  result += f"\n\n({time.time() - start_time:.2f} s)"
132
  yield (
133
  source_amr_display,