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

Function build_idf_from_texts

experiments/baselines/nl_profile/runner.py:164–178  ·  view source on GitHub ↗
(texts: Sequence[Any])

Source from the content-addressed store, hash-verified

162
163
164def build_idf_from_texts(texts: Sequence[Any]) -> Dict[str, float]:
165 doc_frequency: Counter[str] = Counter()
166 doc_count = 0
167 for text in texts:
168 unique_tokens = set(tokenize(text))
169 if not unique_tokens:
170 continue
171 doc_count += 1
172 doc_frequency.update(unique_tokens)
173 if doc_count <= 0:
174 return {}
175 return {
176 token: math.log((doc_count + 1.0) / (freq + 1.0)) + 1.0
177 for token, freq in doc_frequency.items()
178 }
179
180
181def vectorize_text(text: Any, idf: Dict[str, float]) -> Dict[str, float]:

Callers 1

rerank_episodesFunction · 0.70

Calls 1

tokenizeFunction · 0.70

Tested by

no test coverage detected