8
8
from rank_bm25 import BM25Okapi
9
9
import os
10
10
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
12
12
13
13
from factscore .openai_lm import OpenAIModel
14
14
@@ -111,7 +111,7 @@ def get_atomic_facts_from_paragraph(
111
111
(i == len (sentences )- 1 and (sent .startswith ("Please" ) or sent .startswith ("I hope" ) or sent .startswith ("Here are" )))))], cost_estimate = cost_estimate )
112
112
113
113
if cost_estimate :
114
- return atoms_or_estimate
114
+ return cast ( Tuple [ List [ Tuple [ str , List [ str ]]], List [ int ]], atoms_or_estimate )
115
115
else :
116
116
atoms = atoms_or_estimate
117
117
@@ -198,7 +198,7 @@ def get_init_atomic_facts_from_sentence(
198
198
return atoms
199
199
200
200
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 ) -> :
202
202
"""Retrieve the top matching demons for a given query using BM25.
203
203
204
204
Args:
@@ -212,7 +212,7 @@ def best_demos(query: str, bm25: BM25Okapi, demons_sents: List[str], k: int) ->
212
212
"""
213
213
tokenized_query = query .split (" " )
214
214
top_machings = bm25 .get_top_n (tokenized_query , demons_sents , k )
215
- return top_machings
215
+ return cast ( List [ str ], top_machings )
216
216
217
217
def text_to_sentences (text : str ) -> List [str ]:
218
218
"""Transform InstructGPT output into a list of sentences.
@@ -267,7 +267,7 @@ def is_num(text: str) -> bool:
267
267
bool: True if the text is an integer, False otherwise.
268
268
"""
269
269
try :
270
- text = int (text )
270
+ int (text )
271
271
return True
272
272
except Exception :
273
273
return False
@@ -365,7 +365,7 @@ def postprocess_atomic_facts(
365
365
verbs = ["born." , " appointed." , " characterized." , " described." , " known." , " member." , " advocate." , "served." , "elected." ]
366
366
permitted_verbs = ["founding member." ]
367
367
368
- atomic_facts : List [Tuple [ str , List [str ]]] = []
368
+ atomic_facts : List [List [ Sequence [str ]]] = []
369
369
new_atomic_facts : List [Tuple [str , List [str ]]] = []
370
370
new_para_breaks : List [int ] = []
371
371
@@ -429,7 +429,7 @@ def is_integer(s: str) -> bool:
429
429
bool: True if the string is an integer, False otherwise.
430
430
"""
431
431
try :
432
- s = int (s )
432
+ int (s )
433
433
return True
434
434
except Exception :
435
435
return False
0 commit comments