/PREcily_gensim_API

calculating the text similarity but using gensim.

Primary LanguagePython

PREcily_gensim_API

This Flask API calculates the similarity between two text sentences using the Word2Vec model. It preprocesses the text, removes stop words, and computes the cosine similarity between the word embeddings of the sentences.

Prerequisites

  • Python 3.x
  • Flask
  • NLTK
  • Gensim

You can install the required Python packages using the following command:

pip install flask nltk gensim
  1. Run the Flask API using the following command:

    python app.py

    This will start the API locally on http://localhost:8080.

  2. Use a tool like curl or Postman to send POST requests to the API with JSON data containing two text sentences for which you want to calculate similarity. Example:

    curl -X POST -H "Content-Type: application/json" -d '{"text1": "First sentence", "text2": "Second sentence"}' http://localhost:8080
  3. The API will respond with a JSON object containing the similarity score between the two sentences.

Endpoint

  • POST /

    • Request:

      {
        "text1": "First sentence",
        "text2": "Second sentence"
      }
    • Response:

      {
        "similarity score": 0.85
      }