darisdzakwanhoesien2 commited on
Commit
f20b808
·
1 Parent(s): e8b61be

Previous Commit working for Hybrid and resolving Explainable section

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. dummy_sentences.csv +6 -0
app.py CHANGED
@@ -45,6 +45,17 @@ class Sentence:
45
  section_type: str
46
  lang: str
47
 
 
 
 
 
 
 
 
 
 
 
 
48
  SECTION_MAP = {
49
  "TANTANGAN DAN RESPONS TERHADAP ISU KEBERLANJUTAN": "General",
50
  "KINERJA EKONOMI": "Economic",
@@ -497,6 +508,29 @@ class SimpleDLModel(nn.Module):
497
  self.bert = BertModel.from_pretrained(base, output_attentions=True)
498
  self.drop = nn.Dropout(0.2)
499
  self.sent_head = nn.Linear(768, 3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  self.tone_head = nn.Linear(768, 4)
501
  def forward(self, ids, mask):
502
  out = self.bert(ids, attention_mask=mask)
 
45
  section_type: str
46
  lang: str
47
 
48
+ # New function to load dummy sentences
49
+ def load_dummy_sentences():
50
+ try:
51
+ df_dummy = pd.read_csv("dummy_sentences.csv")
52
+ # Ensure Sentence_ID is integer
53
+ df_dummy["Sentence_ID"] = df_dummy["Sentence_ID"].astype(int)
54
+ return df_dummy
55
+ except FileNotFoundError:
56
+ print("dummy_sentences.csv not found. Please create it.")
57
+ return pd.DataFrame()
58
+
59
  SECTION_MAP = {
60
  "TANTANGAN DAN RESPONS TERHADAP ISU KEBERLANJUTAN": "General",
61
  "KINERJA EKONOMI": "Economic",
 
508
  self.bert = BertModel.from_pretrained(base, output_attentions=True)
509
  self.drop = nn.Dropout(0.2)
510
  self.sent_head = nn.Linear(768, 3)
511
+
512
+ def prepare_sentence_dropdown_from_last(text):
513
+ """Return list of sentences from last run (prefer hybrid -> deep -> classical -> rule) or dummy sentences."""
514
+ # Add dummy sentences as a potential source
515
+ df_dummy = load_dummy_sentences()
516
+ if not df_dummy.empty:
517
+ app_state["dummy"] = {"df": df_dummy} # Store dummy sentences in app_state
518
+
519
+ for k in ("hybrid","deep","classical","rule", "dummy"): # Include "dummy" in the preference order
520
+ st = app_state.get(k)
521
+ if not st:
522
+ continue
523
+ if k=="classical" and st is not None:
524
+ # classical stores df_val at "df_val"
525
+ df = st["df_val"]
526
+ else:
527
+ df = st["df"]
528
+ if df is None or df.empty:
529
+ continue
530
+ # produce options "id : snippet"
531
+ opts = [f"{int(r.Sentence_ID)}: {r.Sentence_Text[:120]}" for _, r in df.reset_index().iterrows()]
532
+ return opts
533
+ return ["0: (no sentences available)"]
534
  self.tone_head = nn.Linear(768, 4)
535
  def forward(self, ids, mask):
536
  out = self.bert(ids, attention_mask=mask)
dummy_sentences.csv ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Sentence_ID,Sentence_Text,Section,Section_Type
2
+ 0,"This is a dummy sentence about the economy.",Economic,Economic
3
+ 1,"Another example sentence for environmental concerns.",Environmental,Environmental
4
+ 2,"A third sentence discussing social impact.",Social,Social
5
+ 3,"Governance and transparency are important.",Governance,Governance
6
+ 4,"This sentence is about general sustainability.",General,General