Tfidf Keyword Ranker avatar

Tfidf Keyword Ranker

Pricing

$3.00 / 1,000 results

Go to Apify Store
Tfidf Keyword Ranker

Tfidf Keyword Ranker

Pricing

$3.00 / 1,000 results

Rating

0.0

(0)

Developer

Eichan Jolly

Eichan Jolly

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

4 days ago

Last modified

Categories

Features

Limited permissions

Share

TF-IDF Keyword Ranker

One job: Rank individual words in user-supplied text. This is a deterministic keyword scoring utility, not a language model, semantic analyzer, or keyphrase generator.

Who it is for

Developers preparing search indexes, simple RAG metadata, keyword lists, or interpretable text-analysis pipelines. No login, Apify SDK, external AI service, or user-supplied LLM API key is required. The Python standard library is the only dependency.

How it works (plain words)

  1. Find sequences of Unicode letters, lowercase them, and discard a fixed list of common English words and tokens shorter than minWordLength.
  2. Count how often each remaining word occurs in the target text.
  3. Compute normalized term frequency: target word count divided by the number of retained target tokens.
  4. If referenceTexts were provided, use the target plus reference documents to calculate smoothed inverse document frequency: IDF = ln((N + 1) / (DF + 1)) + 1, and multiply normalized TF by IDF. Only words present in the target text can be returned.
  5. If no reference documents are supplied, N = DF = 1, so IDF = 1: the results are term-frequency only, not informative corpus TF-IDF. The scoring_method output field explicitly says tf_only or tfidf.
  6. Order by unrounded score descending, then keyword alphabetically, and emit one Dataset item per selected keyword.

Scores are relative numerical weights, not calibrated probabilities or a measurement of meaning. Exact output is repeatable for the same input.

Input

FieldTypeDefaultConstraints
textstringrequiredNonempty, max 100,000 characters
referenceTextsarray of strings[]Up to 20 reference texts, each nonempty, max 20,000 characters; total combined length up to 300,000
maxKeywordsinteger101–50 output rows
minWordLengthinteger32–10 Unicode characters

Tiny example (one short text):

{
"text": "Solar panels produce electricity. Solar energy is renewable.",
"maxKeywords": 3
}

The Apify input schema pre-fills only the one short text field; optional settings have defaults.

Output (Dataset items)

For the example above, three items are appended. The actual first item from python src/main.py is:

{
"rank": 1,
"keyword": "solar",
"score": 0.285714,
"frequency": 2,
"document_frequency": 1,
"document_count": 1,
"scoring_method": "tf_only"
}

Every item has the same seven fields. rank starts at 1; frequency is the number of occurrences in the target; document_frequency is the number of input documents containing the keyword; document_count includes the target plus references. See verification/dataset_items.json for all three actual example rows.

Limits and honesty

  • A single text cannot establish meaningful inverse document frequency. Supply several representative reference texts if you need corpus-level weighting.
  • Only unigrams (single words) are emitted. No multiword phrases, lemmatization, stemming, synonyms, named entities, or semantic relevance.
  • The English stopword list is small and fixed. Non-English text may produce low-quality rankings; languages without spaces between words (e.g. Japanese/Chinese) are not properly segmented.
  • Hyphens split words; numbers are skipped. Quoted words, misspellings, technical tokens, and unusual punctuation can affect counts.
  • Results only reflect the input: no search, outside sources, or facts are introduced. Zero qualifying keywords produces a plain-language error and a nonzero exit code.
  • The 1 MB input JSON limit and per-field limits bound processing. Floating scores are rounded to six decimal places in output; sort order uses full precision.

Running locally

Requires Python 3.12+, without pip install:

cd tfidf-keyword-ranker
mkdir -p storage/key_value_stores/default
cp verification/sample_input.json storage/key_value_stores/default/INPUT.json
python src/main.py

Outputs appear at storage/datasets/default/000000001.json etc. Alternatively, set ACTOR_INPUT_JSON to a valid JSON object and run python src/main.py. The local root can be changed with APIFY_LOCAL_STORAGE_DIR. Errors go to standard error as a single Error: ... message (no traceback).

On Apify cloud, the runtime's existing ACTOR_DEFAULT_KEY_VALUE_STORE_ID, ACTOR_INPUT_KEY, ACTOR_DEFAULT_DATASET_ID, and APIFY_TOKEN are used via HTTPS and the Apify storage REST API. The token is provided by the Apify runtime, not supplied in Actor input. No Apify SDK is imported. No other website is contacted.

Verification (included with this Actor)

$python -m unittest discover -s tests -v

tests/test_main.py includes actual python src/main.py subprocess runs with valid INPUT.json and valid ACTOR_INPUT_JSON, invalid-input checks, and a local stub of the Apify storage API. For the saved smoke evidence, see verification/smoke_terminal.txt, verification/sample_input.json, and verification/dataset_items.json. The smoke command was:

mkdir -p verification/smoke_storage/key_value_stores/default
cp verification/sample_input.json verification/smoke_storage/key_value_stores/default/INPUT.json
APIFY_LOCAL_STORAGE_DIR=verification/smoke_storage python src/main.py

Running again appends new local Dataset records. The if __name__ == "__main__": block is intentionally the last statement in src/main.py.

Store categorization and pricing proposal

  • Intended Apify Store category: AI (1 category; suitable for AI data preparation rather than an AI-chatbot clone). Actual Store classification depends on Apify's publishing interface.
  • Suggested billing model: Pay-per-event, per emitted keyword item, if monetization is later implemented. This encourages small maxKeywords values and lets a customer cap output.
  • Current state: No pricing, pay events, or billing are configured or implemented; this folder does not publish an Actor.