A library containing common functions developers used to write repetitevly
Project description
Utility Library
A collection of utility functions for file operations, text processing, AI, and machine learning, designed to streamline common tasks in PyTorch projects.
Features
- Load and save JSON and YAML files.
- Text processing utilities including tokenization and normalization.
- Device management for PyTorch (CPU, CUDA, or MPS).
- Similarity computation for embeddings using cosine similarity.
- Utility functions for data manipulation such as moving averages, safe division, and flattening dictionaries.
Installation
You can install the library via pip:
pip install FuncHub
Usage
File Operations
Load YAML File
from pytorch_utility_library import open_yaml
config = open_yaml('config.yaml', key='model')
Load JSON File
from pytorch_utility_library import open_json
data = open_json('data.json')
Save Data to JSON
from pytorch_utility_library import dump_to_json
dump_to_json('output.json', data)
Save Text to File
from pytorch_utility_library import dump_to_text
dump_to_text('Hello, World!', 'output/hello.txt')
Text Processing
Tokenize Text
from pytorch_utility_library import tokenize
tokens = tokenize("Hello, how are you?")
Normalize Text
from pytorch_utility_library import normalize_text
normalized = normalize_text(" Hello, How Are You? ")
AI and Machine Learning
Get Device
from pytorch_utility_library import get_device
device = get_device()
print(f"Using device: {device}")
Compute Cosine Similarity
from pytorch_utility_library import compute_similarity
similarity = compute_similarity(embedding1, embedding2)
Utility Functions
Calculate Moving Average
from pytorch_utility_library import moving_average
averages = moving_average([1, 2, 3, 4, 5], window_size=3)
Flatten a Nested Dictionary
from pytorch_utility_library import flatten_dict
flat_dict = flatten_dict({'a': {'b': 1, 'c': 2}, 'd': 3})
Logging
The library uses a custom logger for error and information logging. Make sure to configure the logger in your application as needed.
Contributing
Contributions are welcome!
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file funchub-0.1.2.tar.gz.
File metadata
- Download URL: funchub-0.1.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fb74094589d7883280354ba29b63b00ceb2d0362b92a9eb9092ccc197fb79cc
|
|
| MD5 |
dacf2dbf88359802a4e00d7e2852d37b
|
|
| BLAKE2b-256 |
c375955d0f093828083e15626fc52d447f0ea73c42c165209832091247b69a49
|
File details
Details for the file FuncHub-0.1.2-py3-none-any.whl.
File metadata
- Download URL: FuncHub-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ab983b410ff141dd73be8c8df4abc39c0593e11f6d4051d0052b78b2b3fd88a
|
|
| MD5 |
86d6e2932719b2ea7b60ee10fe5e4bc5
|
|
| BLAKE2b-256 |
1a58d6b437ba262e2b9f12b26a5b89e9e42f7a5f5f8ec5036ad2a6b99395fdfb
|