Implementation:AI4Finance Foundation FinGPT extract keywords
| Knowledge Sources | |
|---|---|
| Domains | NLP, Information_Retrieval |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for extracting keywords from financial text using LLM APIs for RAG search query construction provided by the FinGPT RAG pipeline.
Description
The extract_keywords function sends a financial statement to the OpenAI completions API (`text-davinci-003`) with a prompt to extract the 6 most important keywords. These keywords are used as search queries for the news scraping pipeline. The function uses `temperature=0.5`, `max_tokens=60`, and `frequency_penalty=0.8` for controlled, diverse keyword generation.
The G4F alternative (`g4f_tokenization.py`) provides a free version using `gpt-3.5-turbo` via the G4F library with free providers like Vercel.
Usage
Import this function when you need to extract search keywords from financial text:
- RAG keyword extraction: Generating search queries from financial statements.
- Batch processing: Processing CSV files of financial statements row by row.
Code Reference
Source Location
- Repository: FinGPT
- File: fingpt/FinGPT_RAG/multisource_retrieval/external_LLMs/chatGPT_tokenization.py (L9-34), fingpt/FinGPT_RAG/multisource_retrieval/external_LLMs/g4f_tokenization.py (L43-46)
Signature
def extract_keywords(
text: str,
) -> str
Import
from chatGPT_tokenization import extract_keywords # OpenAI backend
# or
from g4f_tokenization import extract_keywords # G4F free backend
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| text | str | Yes | Financial statement to extract keywords from |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | str | Extracted keywords string (6 most important keywords) |
Usage Examples
Extract Keywords for News Search
import os
os.environ["OPENAI_API_KEY"] = "your_key"
from chatGPT_tokenization import extract_keywords
keywords = extract_keywords(
"Apple reported record quarterly revenue of $89.5 billion, "
"driven by strong iPhone sales."
)
print(keywords)
# "Apple, quarterly revenue, iPhone sales, record"
Related Pages
Implements Principle
- Principle:AI4Finance_Foundation_FinGPT_Keyword_Extraction
- Principle:AI4Finance_Foundation_FinGPT_Retrieval_Augmented_Generation