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

Function vectorize_text

experiments/baselines/discourse_aware/runner.py:288–297  ·  view source on GitHub ↗
(text: Any, idf: Dict[str, float])

Source from the content-addressed store, hash-verified

286
287
288def vectorize_text(text: Any, idf: Dict[str, float]) -> Dict[str, float]:
289 counts = Counter(tokenize(text))
290 if not counts:
291 return {}
292 default_idf = math.log(max(2.0, len(idf) + 1.0))
293 vector = {
294 token: (1.0 + math.log(freq)) * idf.get(token, default_idf)
295 for token, freq in counts.items()
296 }
297 return normalize_vector(vector)
298
299
300def normalize_vector(vector: Dict[str, float]) -> Dict[str, float]:

Callers 2

prepare_vectorsMethod · 0.70
facet_similarity_scoreFunction · 0.70

Calls 3

getMethod · 0.80
tokenizeFunction · 0.70
normalize_vectorFunction · 0.70

Tested by

no test coverage detected