MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / build_idf_from_texts

Function build_idf_from_texts

experiments/baselines/scholar_inbox/runner.py:188–202  ·  view source on GitHub ↗
(texts: Sequence[Any])

Source from the content-addressed store, hash-verified

186
187
188def build_idf_from_texts(texts: Sequence[Any]) -> Dict[str, float]:
189 doc_frequency: Counter[str] = Counter()
190 doc_count = 0
191 for text in texts:
192 unique_tokens = set(tokenize(text))
193 if not unique_tokens:
194 continue
195 doc_count += 1
196 doc_frequency.update(unique_tokens)
197 if doc_count <= 0:
198 return {}
199 return {
200 token: math.log((doc_count + 1.0) / (freq + 1.0)) + 1.0
201 for token, freq in doc_frequency.items()
202 }
203
204
205def vectorize_text(text: Any, idf: Dict[str, float]) -> Dict[str, float]:

Callers 2

build_idfFunction · 0.70
rerank_episodesFunction · 0.70

Calls 1

tokenizeFunction · 0.70

Tested by

no test coverage detected