mcpField
K
keyword-extractor

keyword-extractor

github.com/dkyazzentwatwaデータ・データベース12473 回インストール29 週間前に更新
リポジトリ

keyword-extractor について

keyword-extractorは、テキストからキーワードやフレーズを抽出して順位付けするPythonツールです。TF-IDF、RAKE、頻度分析のほか、可視化、一括処理、エクスポートに対応します。

主な機能

  1. 01TF-IDF、RAKE、頻度分析
  2. 02複数語のフレーズ抽出
  3. 03関連度スコアとn-gram
  4. 04組み込みおよびカスタムストップワード
  5. 05ワードクラウドとキーワードチャート
  6. 06一括処理とファイル出力

活用シーン

  1. 01記事や文書の重要語句を抽出
  2. 02複数文書間のキーワードを比較
  3. 03ウェブページの内容からフレーズを調査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill keyword-extractor

インストール後、Claude Code で/keyword-extractorを入力して読み込まれたか確認します。

同梱ファイルscripts/keyword_extractor.pyscripts/requirements.txt

詳細

キーワード抽出

複数のアルゴリズムを使用して、テキスト文書から重要なキーワードやキーフレーズを抽出します。TF-IDF、RAKE、シンプルな頻度分析に対応し、ワードクラウドで可視化できます。

クイックスタート

from scripts.keyword_extractor import KeywordExtractor

# Extract keywords
extractor = KeywordExtractor()
keywords = extractor.extract("Your long text document here...")
print(keywords[:10])  # Top 10 keywords

# From file
keywords = extractor.extract_from_file("document.txt")
extractor.to_wordcloud("keywords.png")

機能

  • 複数のアルゴリズム:TF-IDF、RAKE、頻度ベース
  • キーフレーズ:単語だけでなく、複数語からなるフレーズも抽出
  • スコアリング:順位付けに使用する関連度スコア
  • ストップワードのフィルタリング:組み込みのストップワードとカスタムストップワード
  • N-gram 対応:ユニグラム、バイグラム、トライグラム
  • ワードクラウド:キーワードの重要度を可視化
  • バッチ処理:複数の文書を処理

API リファレンス

初期化
extractor = KeywordExtractor(
    method="tfidf",      # tfidf, rake, frequency
    max_keywords=20,     # Maximum keywords to return
    min_word_length=3,   # Minimum word length
    ngram_range=(1, 3)   # Unigrams to trigrams
)
抽出メソッド
# TF-IDF (best for comparing documents)
keywords = extractor.extract(text, method="tfidf")

# RAKE (best for key phrases)
keywords = extractor.extract(text, method="rake")

# Frequency (simple word counts)
keywords = extractor.extract(text, method="frequency")
結果の形式
keywords = extractor.extract(text)
# Returns list of tuples: [(keyword, score), ...]
# [('machine learning', 0.85), ('data science', 0.72), ...]

# Get just keywords
keyword_list = extractor.get_keywords(text)
# ['machine learning', 'data science', ...]
カスタマイズ
# Add custom stopwords
extractor.add_stopwords(['company', 'product', 'service'])

# Set minimum frequency
extractor.min_frequency = 2

# Filter by part of speech (nouns only)
extractor.pos_filter = ['NN', 'NNS', 'NNP']
可視化
# Generate word cloud
extractor.to_wordcloud("wordcloud.png", colormap="viridis")

# Bar chart of top keywords
extractor.plot_keywords("keywords.png", top_n=15)
エクスポート
# To JSON
extractor.to_json("keywords.json")

# To CSV
extractor.to_csv("keywords.csv")

# To plain text
extractor.to_text("keywords.txt")

CLI の使用方法

# Extract from text
python keyword_extractor.py --text "Your text here" --top 10

# Extract from file
python keyword_extractor.py --input document.txt --method tfidf --output keywords.json

# Generate word cloud
python keyword_extractor.py --input document.txt --wordcloud cloud.png

# Batch process directory
python keyword_extractor.py --input-dir ./docs --output keywords_all.csv
CLI 引数
引数説明デフォルト
--text分析するテキスト-
--input入力ファイルのパス-
--input-dirファイルが格納されたディレクトリ-
--output出力ファイル-
--methodアルゴリズム(tfidf、rake、frequency)tfidf
--topキーワード数20
--ngramsN-gram の範囲(例:「1,2」)1,3
--wordcloudワードクラウドを生成-
--stopwordsカスタムストップワードファイル-

例

記事からのキーワード抽出
extractor = KeywordExtractor(method="tfidf")

article = """
Machine learning is transforming data science. Deep learning models
are achieving state-of-the-art results in natural language processing
and computer vision. Neural networks continue to advance...
"""

keywords = extractor.extract(article, top_n=10)
for keyword, score in keywords:
    print(f"{score:.3f}: {keyword}")
複数の文書を比較
extractor = KeywordExtractor(method="tfidf")

docs = [
    open("doc1.txt").read(),
    open("doc2.txt").read(),
    open("doc3.txt").read()
]

# Extract keywords from each
for i, doc in enumerate(docs):
    keywords = extractor.extract(doc, top_n=5)
    print(f"\nDocument {i+1}:")
    for kw, score in keywords:
        print(f"  {kw}: {score:.3f}")
SEO キーワード調査
extractor = KeywordExtractor(
    method="rake",
    ngram_range=(2, 4),  # Focus on phrases
    max_keywords=30
)

webpage_content = open("page.html").read()
keywords = extractor.extract(webpage_content)

# Filter by score threshold
high_value = [(kw, s) for kw, s in keywords if s > 0.5]
print("High-value keywords for SEO:")
for kw, score in high_value:
    print(f"  {kw}")

アルゴリズムの比較

アルゴリズム最適な用途長所
TF-IDF文書の比較独自性の高い用語を見つけられ、検索に適しています
RAKEキーフレーズ複数語からなる概念を抽出します
頻度手早い概要の把握シンプル、高速で、結果を解釈しやすい

依存関係

scikit-learn>=1.2.0
nltk>=3.8.0
pandas>=2.0.0
matplotlib>=3.7.0
wordcloud>=1.9.0

制限事項

  • 英語に最適化されています(他の言語では、その言語に固有のストップワードが必要です)
  • 非常に短いテキストでは、TF-IDF に十分なデータがない場合があります
  • ドメイン固有の専門用語には、カスタムストップワードの設定が必要な場合があります

コメント