Zum Inhalt springen
uencoder

Berechnen cosine similarity between texts

Cosine similarity measures der angle zwischen Text vectors, indicating semantic similarity. Verwendet in search, clustering, und recommendation.

  1. 1

    Cosine similarity = dot(A, B) / (|A| × |B|), where A and B are term frequency (or TF-IDF) vectors. It ranges from 0 (no shared terms) to 1 (identical direction). Unlike Euclidean distance, it is unaffected by document length — two documents with the same word proportions but different lengths have similarity 1. Convert texts to vectors (TF or TF-IDF), then compute cosine.

  2. 2
    Wortzähler →

    each text in a word frequency vector. The vocabulary is the union of all words in both texts. Each text becomes a vector of word counts. Use TF-IDF weights instead of raw counts for better results — TF-IDF downweights common words konvertieren

  3. 3
    Zeichenhäufigkeit →

    For character-level similarity (useful for code, DNA, non-text), use character frequency vectors instead of word vectors. This captures finer-grained patterns and works for text without word boundaries (CJK languages).

Häufige Fragen

When to use cosine similarity?
For text comparison where document length should not matter: search relevance (query vs document), document clustering, duplicate detection, and recommendation systems. It is the standard similarity metric for text vectors. For tasks where length matters (plagiarism detection), use other metrics.
Cosine vs Jaccard vs Euclidean?
Cosine: angle between vectors (length-invariant) — best for text. Jaccard: intersection/union of sets — best for binary presence/absence. Euclidean: straight-line distance — sensitive to length. For text, cosine is standard; for sets, Jaccard; for spatial data, Euclidean.

Workflows, die diese Aufgabe lösen

Verwandte Tools