Skip to main content

Similar sentence prediction

Project description

PyPI version Python 3

Similar sentence Prediction with more accurate results with your dataset on top of BERT pertained model.

Setup

Install the package

pip install similar-sentences

Methods to know

SimilarSentences(FilePath,Type)

  • FilePath: Reference to model.zip for prediction. Reference to sentences.txt for training.
  • Type: predict or train

.train()

  • Used for training the setences. Which required (".txt", "train") as parameter in SimilarSentences

.predict(InputSentences, NumberOfPrediction, DesiredJsonOutput)

  • Used for predicting the setences. Which required (".zip", "predict") as parameter in SimilarSentences
  • InputSentences: To find the similar sentence for.
  • NumberOfPrediction: Number of results for the prediction
  • DesiredJsonOutput: The output will be in JSON format. simple produces a plain output. detailed produces detailed output with score

.reload()

  • Used for reloading (or) updating the model. Which required (".zip", "predict") as parameter in SimilarSentences

Getting Started

Train the model with your dataset

Prepare your dataset and save the content to sentences.txt

Hi, thanks for contacting.
Hello there!
Hi there, welcome!
Hi, how can I help?
In a few words, how can help?
Hi again, welcome back.
Hi! Welcome back.
Good morning! 
Good afternoon! 
Good evening! 
Good morning! Welcome.
Good afternoon! Welcome.
Good evening! Welcome.
Hello, how can I help?
Welcome.
Welcome back.
Thanks for contacting.
Goodbye!
Thanks for contacting. Goodbye!
Thanks for contacting. Bye!
Happy to help!
Glad I could help!

Supply the sentences to build the model.

from SimilarSentences import SimilarSentences
# Make sure the extension is .txt
model = SimilarSentences('sentences.txt',"train")
model.train()

The code snipet will produce model.zip.

Predicting from your model

Load the model.zip from the training.

from SimilarSentences import SimilarSentences
model = SimilarSentences('model.zip',"predict")
text = 'Hi.How are you doing?'
simple = model.predict(text, 2, "simple")
detailed = model.predict(text, 2, "detailed")
print(simple)
print(detailed)

Output looks like,

#simple output
[
  "Hello there! Did I get that right?",
  "Right Hi, how can I help?"
]

#detailed output
[
  [
    {
      "sentence": "Hello there!",
      "score": 0.938870553799856
    },
    {
      "sentence": "Did I get that right?",
      "score": 0.7910412586610753
    }
  ],
  [
    {
      "sentence": "Right",
      "score": 0.9161810654762793
    },
    {
      "sentence": "Hi, how can I help?",
      "score": 0.7824734658953297
    }
  ]
]

:+1: :sparkles: :camel: :tada: :rocket: :metal: :octocat: HAPPY CODING :octocat: :metal: :rocket: :tada: :camel: :sparkles: :+1:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

similar-sentences-2.9a16.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file similar-sentences-2.9a16.tar.gz.

File metadata

  • Download URL: similar-sentences-2.9a16.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.16

File hashes

Hashes for similar-sentences-2.9a16.tar.gz
Algorithm Hash digest
SHA256 6a541af3c33b7c8bd81713c2b6f5c67684828e403a98287aee3be4fec3c90c8e
MD5 e1c8fe2898913ca2a0b05b93c84e5409
BLAKE2b-256 7f8597b9f319d916059025b695b41110c2d1f204a0b8636899b8d34e6cc5a4bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page