Skip to content

Commit f68b051

Browse files
authored
Update atomic_facts.py
1 parent 0d15386 commit f68b051

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

llments/eval/factscore/atomic_facts.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from rank_bm25 import BM25Okapi
99
import os
1010
from nltk.tokenize import sent_tokenize
11-
from typing import List, Tuple, Optional, Any, Set
11+
from typing import List, Tuple, Optional, Any, Set, cast
1212

1313
from factscore.openai_lm import OpenAIModel
1414

@@ -111,7 +111,7 @@ def get_atomic_facts_from_paragraph(
111111
(i==len(sentences)-1 and (sent.startswith("Please") or sent.startswith("I hope") or sent.startswith("Here are")))))], cost_estimate=cost_estimate)
112112

113113
if cost_estimate:
114-
return atoms_or_estimate
114+
return cast(Tuple[List[Tuple[str, List[str]]], List[int]], atoms_or_estimate)
115115
else:
116116
atoms = atoms_or_estimate
117117

@@ -198,7 +198,7 @@ def get_init_atomic_facts_from_sentence(
198198
return atoms
199199

200200

201-
def best_demos(query: str, bm25: BM25Okapi, demons_sents: List[str], k: int) -> List[str]:
201+
def best_demos(query: str, bm25: BM25Okapi, demons_sents: List[str], k: int) -> :
202202
"""Retrieve the top matching demons for a given query using BM25.
203203
204204
Args:
@@ -212,7 +212,7 @@ def best_demos(query: str, bm25: BM25Okapi, demons_sents: List[str], k: int) ->
212212
"""
213213
tokenized_query = query.split(" ")
214214
top_machings = bm25.get_top_n(tokenized_query, demons_sents, k)
215-
return top_machings
215+
return cast(List[str], top_machings)
216216

217217
def text_to_sentences(text: str) -> List[str]:
218218
"""Transform InstructGPT output into a list of sentences.
@@ -267,7 +267,7 @@ def is_num(text: str) -> bool:
267267
bool: True if the text is an integer, False otherwise.
268268
"""
269269
try:
270-
text = int(text)
270+
int(text)
271271
return True
272272
except Exception:
273273
return False
@@ -365,7 +365,7 @@ def postprocess_atomic_facts(
365365
verbs = ["born.", " appointed.", " characterized.", " described.", " known.", " member.", " advocate.", "served.", "elected."]
366366
permitted_verbs = ["founding member."]
367367

368-
atomic_facts: List[Tuple[str, List[str]]] = []
368+
atomic_facts: List[List[Sequence[str]]] = []
369369
new_atomic_facts: List[Tuple[str, List[str]]] = []
370370
new_para_breaks: List[int] = []
371371

@@ -429,7 +429,7 @@ def is_integer(s: str) -> bool:
429429
bool: True if the string is an integer, False otherwise.
430430
"""
431431
try:
432-
s = int(s)
432+
int(s)
433433
return True
434434
except Exception:
435435
return False

0 commit comments

Comments
 (0)