algo-nlp-similarity

Solid

"Calculate text similarity using lexical and semantic methods for matching and deduplication. Use this skill when the user needs to find similar documents, detect near-duplicates, or measure semantic closeness between texts — even if they say 'how similar are these texts', 'find duplicates', or 'semantic matching'.".

AI & Automation 22 stars 8 forks Updated 6 days ago MIT

Install

View on GitHub

Quality Score: 84/100

Stars 20%
45
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Text Similarity ## Overview Text similarity measures how close two texts are in meaning or surface form. Lexical methods (Jaccard, cosine on TF-IDF) compare word overlap. Semantic methods (sentence embeddings) capture meaning even with different words. Choice depends on whether you need exact matching or meaning matching. ## When to Use **Trigger conditions:** - Finding similar or duplicate documents in a collection - Matching queries to FAQ answers or knowledge base entries - Detecting plagiarism or content reuse **When NOT to use:** - For topic-level grouping (use topic modeling / LDA) - For entity extraction from text (use NER) ## Algorithm ``` IRON LAW: Lexical Similarity ≠ Semantic Similarity "The car is fast" and "The automobile is speedy" have LOW lexical similarity (different words) but HIGH semantic similarity (same meaning). "Bank of the river" and "Bank account" have HIGH lexical similarity but LOW semantic similarity. Choose the method that matches your definition of "similar." ``` ### Phase 1: Input Validation Determine: similarity type needed (lexical or semantic), text preprocessing requirements, scale (pairwise vs all-pairs vs query-to-corpus). **Gate:** Texts preprocessed, method selected. ### Phase 2: Core Algorithm **Lexical methods:** - Jaccard: |A∩B| / |A∪B| on word sets - Cosine on TF-IDF vectors: cos(θ) = (A·B) / (|A|×|B|) **Semantic methods:** - Sentence embeddings: encode texts with sentence-transformers (all-MiniLM-L6-v2) - Cosine similar...

Details

Author
charlieviettq
Repository
charlieviettq/awesome-agent-skill
Created
2 months ago
Last Updated
6 days ago
Language
Python
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category