-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from micvitc/dev/main
added text + label generation
- Loading branch information
Showing
13 changed files
with
605 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,8 +165,8 @@ sad-utils-env/ | |
notebooks/ | ||
|
||
*.ipynb | ||
|
||
*.csv | ||
main.py | ||
test.py | ||
|
||
*.prof | ||
.ruff_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,106 @@ | ||
# Welcome to the mic-toolkit | ||
# Mic Toolkit | ||
|
||
Utilities for internal MIC projects | ||
|
||
## Installation | ||
![PyPI - Version](https://img.shields.io/pypi/v/mic-toolkit) | ||
![Python](https://img.shields.io/badge/python-3.12-blue.svg) | ||
![PyPI - Downloads](https://img.shields.io/pypi/dm/mic-toolkit) | ||
[![CI](https://github.com/micvitc/mic-toolkit/actions/workflows/ci.yaml/badge.svg)](https://github.com/micvitc/mic-toolkit/actions/workflows/ci.yaml) | ||
|
||
Make sure you have a python version>=3.12 | ||
|
||
``` bash | ||
|
||
pip install mic-toolkit | ||
## Overview | ||
|
||
Simple synthetic data generation using LLMs. | ||
|
||
## Features | ||
|
||
- **Text Generation** | ||
- **Label Generation** | ||
|
||
## Installation | ||
|
||
To install Mic Toolkit, use the following command: | ||
|
||
```sh | ||
pip install mic-toolkit | ||
``` | ||
|
||
## Current Utilities | ||
|
||
### Simple Data Generation Pipeline | ||
### Simple Text Generation | ||
|
||
``` py title="text-gen-sample.py" | ||
|
||
|
||
import pandas as pd | ||
from mic_toolkit.synthetic.generation import Generator | ||
|
||
|
||
generator = Generator(endpoint="http://localhost:11434", model="llama3.2:3b-instruct-q4_0") | ||
|
||
``` py title="sample.py" | ||
data = pd.read_csv("data.csv") | ||
|
||
from mic_toolkit.synthetic.generation import TextGenerationPipeline | ||
from datasets import Dataset | ||
output = generator.generate_text(data, system_prompt="Translate the following text to French") | ||
|
||
dataset = Dataset.from_dict( | ||
{"instruction": ["Write a Python program to multiply two numbers."]} | ||
) | ||
print(output) | ||
|
||
``` | ||
Output | ||
|
||
``` | ||
text | ||
0 He heard the crack echo in the late afternoon ... | ||
1 There wasn't a bird in the sky, but that was n... | ||
2 The choice was red, green, or blue. It didn't ... | ||
3 What was beyond the bend in the stream was unk... | ||
4 I guess we could discuss the implications of t... | ||
5 There were about twenty people on the dam. Mos... | ||
output | ||
0 Il entendit le bruit de craquement échoer à la... | ||
1 Il n'y avait pas d'oiseau dans le ciel, mais c... | ||
2 La choix était rouge, vert ou bleu. Il n'a pas... | ||
3 Ce qui se trouvait au-delà de la courbe du rui... | ||
4 Quelles implications auraient la phrase "c'est... | ||
5 Il y avait environ vingt personnes sur la barr... | ||
``` | ||
|
||
### Label Generation | ||
|
||
pipeline = TextGenerationPipeline( | ||
model_name="model_name", | ||
api_key="api_key", | ||
base_url="base_url", | ||
) | ||
|
||
``` py title="text-gen-sample.py" | ||
|
||
distiset = pipeline.run_pipeline(dataset=dataset) | ||
|
||
print(distiset["default"]["train"][0]["generation"]) | ||
import pandas as pd | ||
from mic_toolkit.synthetic.generation import Generator | ||
|
||
|
||
generator = Generator(endpoint="http://localhost:11434", model="llama3.2:3b-instruct-q4_0") | ||
|
||
data = pd.read_csv("data.csv") | ||
|
||
output = generator.generate_labels(data=data, labels=["Europe", "Asia", "Africa", "America", "Oceania"], query="Which continent does the following country belong to?") | ||
|
||
print(output) | ||
|
||
``` | ||
|
||
Output | ||
|
||
``` | ||
country label | ||
0 France Europe | ||
1 Argentina America | ||
2 United States America | ||
3 Canada America | ||
4 Mexico America | ||
5 Brazil America | ||
6 United Kingdom Europe | ||
7 Germany Europe | ||
8 Italy Europe | ||
9 Spain Europe | ||
10 Australia Oceania | ||
11 Japan Asia | ||
``` |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import cProfile | ||
|
||
|
||
def profiler(func): | ||
def wrapper(*args, **kwargs): | ||
profile = cProfile.Profile() | ||
profile.enable() | ||
result = func(*args, **kwargs) | ||
profile.disable() | ||
profile.print_stats(sort="cumtime") | ||
profile.dump_stats(f"{func.__name__}.prof") | ||
return result | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.