モデル概要
モデル特徴
モデル能力
使用事例
🚀 キーフレーズ生成モデル: T5-small-inspec
キーフレーズ抽出は、文書から重要なキーフレーズを抽出するテキスト分析技術です。これらのキーフレーズにより、人間は文書を完全に読まなくても、内容を迅速かつ簡単に理解できます。当初、キーフレーズ抽出は主に人間のアノテーターが行っていました。彼らは文書を詳細に読み、最も重要なキーフレーズを書き留めました。ただし、大量の文書を扱う場合、このプロセスには多くの時間がかかるという欠点があります⏳。
ここで人工知能🤖が登場します。現在、統計的および言語的特徴を利用した古典的な機械学習手法が、抽出プロセスに広く使用されています。しかし、ディープラーニングにより、これらの古典的手法よりもテキストの意味をより適切に捉えることが可能になりまし。古典的手法は、テキスト内の単語の頻度、出現回数、順序を見ますが、ニューラルアプローチでは、テキスト内の単語の長期的な意味依存関係と文脈を捉えることができます。
🚀 クイックスタート
このキーフレーズ生成モデルについて、以下で詳しく説明します。
✨ 主な機能
- このモデルは、T5-smallモデルをベースに、Inspecデータセットでファインチューニングされています。
- キーフレーズ生成トランスフォーマーは、キーフレーズを生成するテキスト生成問題としてファインチューニングされています。結果は、指定された区切り文字(例:";")で区切られたキーフレーズの連結文字列となります。
- このモデルは、存在するキーフレーズと存在しないキーフレーズの両方を生成することができます。
📦 インストール
このモデルを使用するには、必要なライブラリをインストールする必要があります。以下のコードを実行して、必要なライブラリをインストールします。
# Model parameters
from transformers import (
Text2TextGenerationPipeline,
AutoModelForSeq2SeqLM,
AutoTokenizer,
)
class KeyphraseGenerationPipeline(Text2TextGenerationPipeline):
def __init__(self, model, keyphrase_sep_token=";", *args, **kwargs):
super().__init__(
model=AutoModelForSeq2SeqLM.from_pretrained(model),
tokenizer=AutoTokenizer.from_pretrained(model),
*args,
**kwargs
)
self.keyphrase_sep_token = keyphrase_sep_token
def postprocess(self, model_outputs):
results = super().postprocess(
model_outputs=model_outputs
)
return [[keyphrase.strip() for keyphrase in result.get("generated_text").split(self.keyphrase_sep_token) if keyphrase != ""] for result in results]
# Load pipeline
model_name = "ml6team/keyphrase-generation-t5-small-inspec"
generator = KeyphraseGenerationPipeline(model=model_name)
💻 使用例
基本的な使用法
text = """
Keyphrase extraction is a technique in text analysis where you extract the
important keyphrases from a document. Thanks to these keyphrases humans can
understand the content of a text very quickly and easily without reading it
completely. Keyphrase extraction was first done primarily by human annotators,
who read the text in detail and then wrote down the most important keyphrases.
The disadvantage is that if you work with a lot of documents, this process
can take a lot of time.
Here is where Artificial Intelligence comes in. Currently, classical machine
learning methods, that use statistical and linguistic features, are widely used
for the extraction process. Now with deep learning, it is possible to capture
the semantic meaning of a text even better than these classical methods.
Classical methods look at the frequency, occurrence and order of words
in the text, whereas these neural approaches can capture long-term
semantic dependencies and context of words in a text.
""".replace("\n", " ")
keyphrases = generator(text)
print(keyphrases)
# Output
[['keyphrase extraction', 'text analysis', 'artificial intelligence', 'classical machine learning methods']]
📚 ドキュメント
モデルの説明
このモデルは、T5-smallモデルをベースに、Inspecデータセットでファインチューニングされています。キーフレーズ生成トランスフォーマーは、キーフレーズを生成するテキスト生成問題としてファインチューニングされています。結果は、指定された区切り文字(例:";")で区切られたキーフレーズの連結文字列となります。このモデルは、存在するキーフレーズと存在しないキーフレーズの両方を生成することができます。
想定される用途と制限
🛑 制限事項
- このキーフレーズ生成モデルは非常にドメイン固有であり、科学論文の要約に対して非常に良好な性能を発揮します。他のドメインでの使用は推奨されませんが、テストすることは自由です。
- 英語の文書にのみ対応しています。
- 時には出力が意味を成さないことがあります。
❓ 使い方
コードの使用例は「💻 使用例」を参照してください。
学習データセット
Inspecは、1998年から2002年に発行された、コンピュータと制御、情報技術の科学分野の2000件の英語の科学論文から構成されるキーフレーズ抽出/生成データセットです。キーフレーズは、専門のインデクサーまたは編集者によってアノテーション付けされています。
詳細な情報は、論文を参照してください。
学習手順
学習パラメータ
パラメータ | 値 |
---|---|
学習率 | 5e-5 |
エポック数 | 50 |
早期終了の許容回数 | 1 |
前処理
データセット内の文書は、すでに対応するキーフレーズとともに単語のリストに前処理されています。必要なのは、トークン化と、すべてのキーフレーズを特定の区切り文字(;
)で1つの文字列に結合することだけです。
from datasets import load_dataset
from transformers import AutoTokenizer
# Tokenizer
tokenizer = AutoTokenizer.from_pretrained("t5-small", add_prefix_space=True)
# Dataset parameters
dataset_full_name = "midas/inspec"
dataset_subset = "raw"
dataset_document_column = "document"
keyphrase_sep_token = ";"
def preprocess_keyphrases(text_ids, kp_list):
kp_order_list = []
kp_set = set(kp_list)
text = tokenizer.decode(
text_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
)
text = text.lower()
for kp in kp_set:
kp = kp.strip()
kp_index = text.find(kp.lower())
kp_order_list.append((kp_index, kp))
kp_order_list.sort()
present_kp, absent_kp = [], []
for kp_index, kp in kp_order_list:
if kp_index < 0:
absent_kp.append(kp)
else:
present_kp.append(kp)
return present_kp, absent_kp
def preprocess_fuction(samples):
processed_samples = {"input_ids": [], "attention_mask": [], "labels": []}
for i, sample in enumerate(samples[dataset_document_column]):
input_text = " ".join(sample)
inputs = tokenizer(
input_text,
padding="max_length",
truncation=True,
)
present_kp, absent_kp = preprocess_keyphrases(
text_ids=inputs["input_ids"],
kp_list=samples["extractive_keyphrases"][i]
+ samples["abstractive_keyphrases"][i],
)
keyphrases = present_kp
keyphrases += absent_kp
target_text = f" {keyphrase_sep_token} ".join(keyphrases)
with tokenizer.as_target_tokenizer():
targets = tokenizer(
target_text, max_length=40, padding="max_length", truncation=True
)
targets["input_ids"] = [
(t if t != tokenizer.pad_token_id else -100)
for t in targets["input_ids"]
]
for key in inputs.keys():
processed_samples[key].append(inputs[key])
processed_samples["labels"].append(targets["input_ids"])
return processed_samples
# Load dataset
dataset = load_dataset(dataset_full_name, dataset_subset)
# Preprocess dataset
tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
後処理
後処理では、キーフレーズの区切り文字に基づいて文字列を分割する必要があります。
def extract_keyphrases(examples):
return [example.split(keyphrase_sep_token) for example in examples]
評価結果
従来の評価方法は、精度、再現率、F1スコア@k,mです。ここで、kは最初のk個の予測キーフレーズを表し、mは予測キーフレーズの平均数を表します。キーフレーズ生成では、F1@Oも見ます。ここで、Oは正解キーフレーズの数を表します。
このモデルは、Inspecテストセットで以下の結果を達成しています。
抽出型キーフレーズ
データセット | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M | P@O | R@O | F1@O |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Inspecテストセット | 0.33 | 0.31 | 0.29 | 0.17 | 0.31 | 0.20 | 0.41 | 0.31 | 0.32 | 0.28 | 0.28 | 0.28 |
抽象型キーフレーズ
データセット | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M | P@O | R@O | F1@O |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Inspecテストセット | 0.05 | 0.09 | 0.06 | 0.03 | 0.09 | 0.04 | 0.08 | 0.09 | 0.07 | 0.06 | 0.06 | 0.06 |
🚨 問題の報告
コミュニティタブで自由に議論を開始してください。
📄 ライセンス
このプロジェクトはMITライセンスの下で公開されています。








