Krish Patel commited on
Commit
4b98068
·
1 Parent(s): 8ea2142

debugging2

Browse files
Files changed (1) hide show
  1. final.py +40 -0
final.py CHANGED
@@ -89,6 +89,45 @@ def extract_entities(text, nlp):
89
  entities = [(ent.text, ent.label_) for ent in doc.ents]
90
  return entities
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  def update_knowledge_graph(text, is_real, knowledge_graph, nlp, save=True, push_to_hf=True):
93
  """Update knowledge graph with new information"""
94
  entities = extract_entities(text, nlp)
@@ -117,6 +156,7 @@ def update_knowledge_graph(text, is_real, knowledge_graph, nlp, save=True, push_
117
  )
118
  else:
119
  knowledge_graph[entity1][entity2]['weight'] += 1
 
120
  if save:
121
  from save_model import save_knowledge_graph, push_to_huggingface
122
  filepath = save_knowledge_graph(knowledge_graph)
 
89
  entities = [(ent.text, ent.label_) for ent in doc.ents]
90
  return entities
91
 
92
+ # def update_knowledge_graph(text, is_real, knowledge_graph, nlp, save=True, push_to_hf=True):
93
+ # """Update knowledge graph with new information"""
94
+ # entities = extract_entities(text, nlp)
95
+ # for entity, entity_type in entities:
96
+ # if not knowledge_graph.has_node(entity):
97
+ # knowledge_graph.add_node(
98
+ # entity,
99
+ # type=entity_type,
100
+ # real_count=1 if is_real else 0,
101
+ # fake_count=0 if is_real else 1
102
+ # )
103
+ # else:
104
+ # if is_real:
105
+ # knowledge_graph.nodes[entity]['real_count'] += 1
106
+ # else:
107
+ # knowledge_graph.nodes[entity]['fake_count'] += 1
108
+
109
+ # for i, (entity1, _) in enumerate(entities):
110
+ # for entity2, _ in entities[i+1:]:
111
+ # if not knowledge_graph.has_edge(entity1, entity2):
112
+ # knowledge_graph.add_edge(
113
+ # entity1,
114
+ # entity2,
115
+ # weight=1,
116
+ # is_real=is_real
117
+ # )
118
+ # else:
119
+ # knowledge_graph[entity1][entity2]['weight'] += 1
120
+ # if save:
121
+ # from save_model import save_knowledge_graph, push_to_huggingface
122
+ # filepath = save_knowledge_graph(knowledge_graph)
123
+
124
+ # # Push to Hugging Face if requested
125
+ # if push_to_hf:
126
+ # repo_id = os.getenv("HF_REPO_ID", "HeheBoi0769/Nexus_NLP_model")
127
+ # push_to_huggingface(filepath, repo_id)
128
+
129
+ # return knowledge_graph
130
+
131
  def update_knowledge_graph(text, is_real, knowledge_graph, nlp, save=True, push_to_hf=True):
132
  """Update knowledge graph with new information"""
133
  entities = extract_entities(text, nlp)
 
156
  )
157
  else:
158
  knowledge_graph[entity1][entity2]['weight'] += 1
159
+
160
  if save:
161
  from save_model import save_knowledge_graph, push_to_huggingface
162
  filepath = save_knowledge_graph(knowledge_graph)