
2026/03/06 5:18
**GLiNER2:統一スキーマベース情報抽出**
RSS: https://news.ycombinator.com/rss
要約▶
Japanese Translation:
## Summary: GLiNER2は、205 Mパラメータのコンパクトで統一されたモデルであり、名前付きエンティティ認識(Named Entity Recognition)、テキスト分類(Text Classification)、構造化データ抽出(Structured Data Extraction)および関係抽出(Relation Extraction)をすべて1回の前方パスで実行できます。GPUや外部APIに依存せず、CPU上で効率的に動作します。より大きなワークロードには340 Mの「fastino/gliner2-large-v1」バリアントが利用可能であり、さらに別途1Bモデル(GLiNER XL)はクラウドAPI経由でアクセスできます。 典型的な使用方法は次のとおりです: ```python extractor = GLiNER2.from_pretrained("fastino/gliner2-base-v1") entities = extractor.extract_entities(text, ["company","person","product","location"])
モデルはオプションで信頼度スコア、文字列範囲データを出力し、多ラベル分類の閾値もサポートします。構造化抽出はJSONスキーマ構文(
field::type::description)によって駆動され、製品や金融取引などの複雑なエンティティを解析できます。関係抽出では方向付きタプル(例:works_for、located_in)が返され、説明、信頼度、および範囲情報も付随します。
バッチ機能(
batch_extract_entities、batch_extract_relations)により、多数のドキュメントに対して効率的な推論が可能です。トレーニングパイプラインはJSONLデータセットまたはLoRAアダプターを使用したドメイン適応による完全なファインチューニングをサポートします。RegexValidatorを添付することで、メールアドレス、URL、電話番号などの抽出フィールドをカスタム正規表現ルールでフィルタリングできます。
GLiNER2はApache License 2.0の下でリリースされ、EMNLP‑2025論文に記載されています。そのシングルパスかつCPUフレンドリーな設計は、金融・eコマース・エンタープライズ検索など、費用対効果の高いNLPパイプラインにとって魅力的です。
本文
GLiNER 2 – 統合抽出ツールキット
GLiNER 2 は 名前付きエンティティ認識(NER)、テキスト分類、構造化データ抽出、そして 関係抽出 を 1 つの 205 M パラメータモデルで統合し、CPU 上でも効率的に動作します。
すぐにインストール&インポート
pip install gliner2
from gliner2 import GLiNER2
ワンライナーでの使用例
extractor = GLiNER2.from_pretrained("fastino/gliner2-base-v1") text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday." result = extractor.extract_entities( text, ["company", "person", "product", "location"] ) print(result) # {'entities': {'company': ['Apple'], 'person': ['Tim Cook'], # 'product': ['iPhone 15'], 'location': ['Cupertino']}}
API アクセス(GPU 不要)
extractor = GLiNER2.from_api() # PIONEER_API_KEY 環境変数を使用 result = extractor.extract_entities( "OpenAI CEO Sam Altman announced GPT-5 at their San Francisco headquarters.", ["company", "person", "product", "location"] )
利用可能なモデル(Hugging Face)
| モデル | パラメータ数 | 用途 |
|---|---|---|
| 205 M | 抽出 / 分類 |
| 340 M | 抽出 / 分類 |
コア機能
1. エンティティ抽出
extractor.extract_entities( text, ["medication", "dosage", "symptom", "time"], include_confidence=True, # 任意 include_spans=True # 任意 )
2. テキスト分類
# 単一ラベル extractor.classify_text(text, {"sentiment": ["positive","negative","neutral"]}) # 閾値付きマルチラベル schema = extractor.create_schema().classification( "topics", ["technology", "business", "health"], multi_label=True, cls_threshold=0.3 )
3. 構造化データ抽出
extractor.extract_json( text, { "product": [ "name::str", "storage::str", "processor::str", "price::str", "colors::list" ] }, include_confidence=True, include_spans=True )
4. 関係抽出
extractor.extract_relations( text, ["works_for", "lives_in"], include_confidence=True, include_spans=True )
マルチタスクスキーマ構成
すべての抽出タイプを網羅する単一スキーマを作成します。
schema = ( extractor.create_schema() .entities({ "person": "人名、経営者、個人", "company": "組織名", "product": "製品またはサービス" }) .classification("sentiment", ["positive","negative","neutral"]) .relations(["works_for","located_in"]) .structure("product_info") .field("name", dtype="str") .field("price", dtype="str") .field("features", dtype="list") ) results = extractor.extract(text, schema)
事例シナリオ
| ドメイン | サンプルテキスト | 抽出結果 |
|---|---|---|
| 金融 | “Transaction Report: Goldman Sachs processed a $2.5M equity trade for Tesla Inc.” | ブローカー、金額、証券等を含む構造化 JSON |
| 医療 | “Patient Sarah Johnson prescribed Lisinopril 10mg daily.” | 患者情報 + 処方箋 |
| 法務 | “Service Agreement between TechCorp LLC and DataSystems Inc., effective January 1, 2024.” | エンティティ、契約種別、関係、条項 |
高度な設定
カスタム信頼度閾値
extractor.extract_json( text, {"financial_data": ["account_number::str", "amount::str"]}, threshold=0.9 # すべてのフィールドに適用 )
スキーマ別フィールドごとの閾値
schema = ( extractor.create_schema() .structure("sensitive_data") .field("ssn", dtype="str", threshold=0.95) .field("email", dtype="str", threshold=0.8) )
正規表現バリデータ(データ品質)
from gliner2 import RegexValidator email_validator = RegexValidator(r"^[\w.-]+@[\w.-]+\.\w+$") schema = ( extractor.create_schema() .structure("contact") .field("email", dtype="str", validators=[email_validator]) )
複数のバリデータをチェーン可能で、すべてが合格しなければ失敗します。
バッチ処理
texts = ["Google's Sundar Pichai...", "Microsoft CEO Satya..."] results = extractor.batch_extract_entities( texts, ["company","person"], include_confidence=True, batch_size=8 )
関係抽出やその他タスク用の同様の関数も利用可能です。
自分でモデルを学習させる
from gliner2.training.trainer import GLiNER2Trainer, TrainingConfig from gliner2.training.data import InputExample examples = [ InputExample( text="John works at Google in California.", entities={"person": ["John"], "company": ["Google"], "location": ["California"]} ), # 追加例... ] model = GLiNER2.from_pretrained("fastino/gliner2-base-v1") config = TrainingConfig(output_dir="./output", num_epochs=10, batch_size=8) trainer = GLiNER2Trainer(model, config) trainer.train(train_data=examples)
LoRA(パラメータ効率の高いファインチューニング)がサポートされており、アダプタは約5 MBで済みます(450 MB ではなく)。
ライセンス & 引用
- ライセンス: Apache 2.0
- 引用例:
@inproceedings{zaratiana-etal-2025-gliner2, title={GLiNER2: Schema‑Driven Multi‑Task Learning for Structured Information Extraction}, author={Zaratiana, Urchade and Pasternak, Gil and Boyd, Oliver and Hurn‑Maloney, George and Lewis, Ash}, booktitle={Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing: System Demonstrations}, year=2025, pages={130--140} }
データから洞察を抽出する準備はできましたか?
pip install gliner2