Skip to main content

AI made easy. Based on pytorch.

Project description

Pytrainer

AI made Easy.

Tutorials

Train and Save a Model

from pytrainer.text import TextAI

# Create an instance of TextAI
ai = TextAI()

# Define some simple training data (input-output pairs)
training_data = {
    "Hello": "Hi there!",
    "How are you?": "I'm good, thank you!",
    "What's your name?": "I am TextAI."
}

# Train the model
ai.train(training_data, epochs=10, batch_size=1, learning_rate=0.001)

# Save the trained model
ai.save('trained_model.json')

Load and Prompt the Model

from pytrainer.text import TextAI

# Create a new instance of TextAI and load the trained model
ai_new = TextAI()
ai_new.load('trained_model.json')

# Generate a response to a new prompt
response = ai_new.prompt("What's your name?")
print(response)

Classes

TextAI

from pytrainer.text import TextAI

train(self, data, epochs=10, batch_size=1, learning_rate=0.001)

  • Arguments:
    • data: A dictionary of input-output pairs for training (required).
    • epochs: The number of training epochs (default is 10).
    • batch_size: The batch size used during training (default is 1).
    • learning_rate: The learning rate for the optimizer (default is 0.001).

prompt(self, input_text, max_length=50, temperature=0.5)

  • Arguments:
    • input_text: The text prompt to generate a response for (required).
    • max_length: The maximum length of the generated response (default is 50).
    • temperature: Controls the randomness of the generated text (default is 0.7).
    • nearestPunctuation: Should a word be rounded to the same word with different punctuation, if that word is not tokenized? (defualt is False)

save(self, path)

  • Arguments:
    • path: The file path to save the model data (required).

load(self, path)

  • Arguments:
    • path: The file path from which to load the model data (required).

Known Issues:

(Fixed errors will be removed next update, and moved to change log in github.)

  • Exploding gradients during training of over 30 epochs, resulting in NaN errors when prompting. FIXED
  • When prompting, using an un-tokenized word will fail. FIXED
    • Note: There is a new option to map un-tokenized words to the same word with different punctation, if one was tokenized. Otherwise, it will return nothing.

Planned Features:

  • Individual classes for Tokenizers, allowing them to be customized.
  • Option for built-in tokenizers, so the trained model is backward compatible with pytorch.

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

pytrainer-1.0.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytrainer-1.0.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file pytrainer-1.0.0.tar.gz.

File metadata

  • Download URL: pytrainer-1.0.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.0

File hashes

Hashes for pytrainer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 486dc5a485b2e46145d3618b65b36855f6ac1b00e4a485498ff1e619e535f6fa
MD5 91a3fcc74cdcbdd7d0ef32ea21e25190
BLAKE2b-256 a538b13b4eb0982a42fe4a8220a93855b303d938c8c05bcdc36672fc9b209c37

See more details on using hashes here.

File details

Details for the file pytrainer-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pytrainer-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.0

File hashes

Hashes for pytrainer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff3e0e3a6df00495e66ef4a50ec569e278cdfb596b2ffef81549fc5196c78285
MD5 863ba7acad72d821e0de07b57b7b9ac9
BLAKE2b-256 4ae8f394b3a06d2e0fa021339f8922579d35985160ee7093dddbea7fce1c7c0e

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