pcs-annotator 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: pcs-annotator
3
+ Version: 0.1.3
4
+ Summary: A Python library for classification tasks using multiple LLMs
5
+ Project-URL: Homepage, https://github.com/salsina/PCS-Python-Library
6
+ Project-URL: Issues, https://github.com/salsina/PCS-Python-Library/issues
7
+ Author-email: Sina Salimian <sina99.sn@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.8
13
+ Requires-Dist: langchain
14
+ Requires-Dist: langchain-anthropic
15
+ Requires-Dist: langchain-community
16
+ Requires-Dist: langchain-groq
17
+ Requires-Dist: langchain-huggingface
18
+ Requires-Dist: langchain-openai
19
+ Requires-Dist: python-dotenv
20
+ Description-Content-Type: text/markdown
21
+
22
+ # PCS Annotator: A Python Library for Classification Tasks Using Multiple LLMs
23
+
24
+ ## How to Install
25
+
26
+ ```bash
27
+ pip install pcs-annotator
28
+ ```
29
+
30
+ ## How to Use
31
+
32
+ ```python
33
+ from pcs_annotator import PCS
34
+ ```
35
+
36
+ ### Create a Prompt for Classification Tasks
37
+
38
+ ```python
39
+ prompt = """Analyze the news article and determine whether it is 'Fake' or 'Real.'
40
+ Label the article using the tag format: <label>Fake</label> or <label>Real</label>.
41
+ Afterward, provide your reasoning after the “<reasoning>” tag and close it with "</reasoning>".
42
+ Respond only with the label and the reasoning.
43
+ """
44
+ ```
45
+
46
+
47
+
48
+
49
+
50
+ ## 🔧 Customizing Hyperparameters
51
+
52
+ The `PCS` class allows you to customize various hyperparameters, including the choice of annotator models, text mutator models, and API keys for different LLM providers.
53
+
54
+ ### 📌 Example Usage
55
+ ```python
56
+ PCS(
57
+ prompt="Your classification prompt here",
58
+ dataset_path="path/to/dataset.csv",
59
+ annotators=["llama3-8b-8192", "mistralai/Mistral-7B-Instruct-v0.3", "google/gemma-2-9b-it"],
60
+ textmutator="llama-3.1-8b-instant",
61
+ GROQ_API_KEY=None,
62
+ OPENAI_API_KEY=None,
63
+ ANTHROPIC_API_KEY=None,
64
+ HUGGINGFACE_API_KEY=None
65
+ )
66
+ ```
67
+
68
+ # Configuration
69
+ ## 🔹 Training Dataset (`dataset_path`)
70
+
71
+ You will need a CSV file with two columns: `label` and `text` to ensure better annotation, as the data is used to train the LLMs.
72
+
73
+
74
+ ## 🔹 Annotators (`annotators`)
75
+ Defines the list of LLMs used for annotation.
76
+ * **Default Models**:
77
+ * `"llama3-8b-8192"`
78
+ * `"mistralai/Mistral-7B-Instruct-v0.3"`
79
+ * `"google/gemma-2-9b-it"`
80
+ * **Customization**:
81
+ * You can add, remove, or modify the annotators by passing a list of model names.
82
+
83
+ ## 🔹 Text Mutator (`textmutator`)
84
+ Determines the LLM used for generating text mutations.
85
+ * **Default Model**: `"llama-3.1-8b-instant"`
86
+ * **Customization**:
87
+ * You can replace it by passing a different model name as a string.
88
+
89
+ ## 🔹 API Keys
90
+ To access certain LLM models, you need to provide API keys. These can be passed as arguments during initialization or set as environment variables in a `.env` file.
91
+
92
+ | API Key | Purpose |
93
+ |---------|---------|
94
+ | `GROQ_API_KEY` | Required for **Llama models**. Set via argument or `.env` file. |
95
+ | `OPENAI_API_KEY` | Required for **OpenAI models** (e.g., `"gpt-4"`). |
96
+ | `ANTHROPIC_API_KEY` | Required for **Anthropic models** (e.g., `"claude-3-5-sonnet-20241022"`). |
97
+ | `HUGGINGFACE_API_KEY` | Required for **Mistral and Google Gemma models**. |
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ ### Annotate a New Text
106
+
107
+ ```python
108
+ print(pcs.annotate("America is a country"))
@@ -0,0 +1,87 @@
1
+ # PCS Annotator: A Python Library for Classification Tasks Using Multiple LLMs
2
+
3
+ ## How to Install
4
+
5
+ ```bash
6
+ pip install pcs-annotator
7
+ ```
8
+
9
+ ## How to Use
10
+
11
+ ```python
12
+ from pcs_annotator import PCS
13
+ ```
14
+
15
+ ### Create a Prompt for Classification Tasks
16
+
17
+ ```python
18
+ prompt = """Analyze the news article and determine whether it is 'Fake' or 'Real.'
19
+ Label the article using the tag format: <label>Fake</label> or <label>Real</label>.
20
+ Afterward, provide your reasoning after the “<reasoning>” tag and close it with "</reasoning>".
21
+ Respond only with the label and the reasoning.
22
+ """
23
+ ```
24
+
25
+
26
+
27
+
28
+
29
+ ## 🔧 Customizing Hyperparameters
30
+
31
+ The `PCS` class allows you to customize various hyperparameters, including the choice of annotator models, text mutator models, and API keys for different LLM providers.
32
+
33
+ ### 📌 Example Usage
34
+ ```python
35
+ PCS(
36
+ prompt="Your classification prompt here",
37
+ dataset_path="path/to/dataset.csv",
38
+ annotators=["llama3-8b-8192", "mistralai/Mistral-7B-Instruct-v0.3", "google/gemma-2-9b-it"],
39
+ textmutator="llama-3.1-8b-instant",
40
+ GROQ_API_KEY=None,
41
+ OPENAI_API_KEY=None,
42
+ ANTHROPIC_API_KEY=None,
43
+ HUGGINGFACE_API_KEY=None
44
+ )
45
+ ```
46
+
47
+ # Configuration
48
+ ## 🔹 Training Dataset (`dataset_path`)
49
+
50
+ You will need a CSV file with two columns: `label` and `text` to ensure better annotation, as the data is used to train the LLMs.
51
+
52
+
53
+ ## 🔹 Annotators (`annotators`)
54
+ Defines the list of LLMs used for annotation.
55
+ * **Default Models**:
56
+ * `"llama3-8b-8192"`
57
+ * `"mistralai/Mistral-7B-Instruct-v0.3"`
58
+ * `"google/gemma-2-9b-it"`
59
+ * **Customization**:
60
+ * You can add, remove, or modify the annotators by passing a list of model names.
61
+
62
+ ## 🔹 Text Mutator (`textmutator`)
63
+ Determines the LLM used for generating text mutations.
64
+ * **Default Model**: `"llama-3.1-8b-instant"`
65
+ * **Customization**:
66
+ * You can replace it by passing a different model name as a string.
67
+
68
+ ## 🔹 API Keys
69
+ To access certain LLM models, you need to provide API keys. These can be passed as arguments during initialization or set as environment variables in a `.env` file.
70
+
71
+ | API Key | Purpose |
72
+ |---------|---------|
73
+ | `GROQ_API_KEY` | Required for **Llama models**. Set via argument or `.env` file. |
74
+ | `OPENAI_API_KEY` | Required for **OpenAI models** (e.g., `"gpt-4"`). |
75
+ | `ANTHROPIC_API_KEY` | Required for **Anthropic models** (e.g., `"claude-3-5-sonnet-20241022"`). |
76
+ | `HUGGINGFACE_API_KEY` | Required for **Mistral and Google Gemma models**. |
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+ ### Annotate a New Text
85
+
86
+ ```python
87
+ print(pcs.annotate("America is a country"))
@@ -13,10 +13,8 @@ from langchain_huggingface import HuggingFaceEndpoint
13
13
 
14
14
  class LLM:
15
15
  def __init__(self, model_name, token=None):
16
- if token:
17
- self.key = token
18
- else:
19
- load_dotenv()
16
+ self.key = token
17
+ load_dotenv()
20
18
  self.model_name = model_name
21
19
  self.llm = self._initialize_model()
22
20
  parser = StrOutputParser()
@@ -9,7 +9,7 @@ from tqdm import tqdm
9
9
 
10
10
 
11
11
  class PCS:
12
- def __init__(self, prompt, dataset_path, annotators=["llama3-8b-8192", "mistralai/Mistral-7B-Instruct-v0.3", "google/gemma-2-9b-it"], GROQ_API_KEY=None, OPENAI_API_KEY=None, ANTHROPIC_API_KEY=None, HUGGINGFACE_API_KEY=None):
12
+ def __init__(self, prompt, dataset_path, annotators=["llama3-8b-8192", "mistralai/Mistral-7B-Instruct-v0.3", "google/gemma-2-9b-it"], textmutator="llama-3.1-8b-instant", GROQ_API_KEY=None, OPENAI_API_KEY=None, ANTHROPIC_API_KEY=None, HUGGINGFACE_API_KEY=None):
13
13
  self.prompt=prompt
14
14
  if os.path.exists(dataset_path):
15
15
  self.dataset_path = dataset_path
@@ -17,7 +17,18 @@ class PCS:
17
17
  raise FileNotFoundError(f"Invalid dataset path {dataset_path}")
18
18
  self.annotator_model_names = annotators
19
19
  self.annotators = []
20
- self.textMutator = TextMutator()
20
+
21
+ if textmutator.startswith("llama"):
22
+ self.textMutator = TextMutator(model_name=textmutator, token=GROQ_API_KEY)
23
+ elif textmutator.startswith("gpt"):
24
+ self.textMutator = TextMutator(model_name=textmutator, token=OPENAI_API_KEY)
25
+ elif textmutator.startswith("claude"):
26
+ self.textMutator = TextMutator(model_name=textmutator, token=ANTHROPIC_API_KEY)
27
+ elif textmutator.startswith("mistral") or textmutator.startswith("google"):
28
+ self.textMutator = TextMutator(model_name=textmutator, token=HUGGINGFACE_API_KEY)
29
+ else:
30
+ raise ValueError(f"Unsupported text mutator model name: {textmutator}")
31
+
21
32
 
22
33
  self.annotations_filename = self.dataset_path.rsplit(".csv", 1)[0] + "_annotations.csv"
23
34
  self.dataset = pd.read_csv(dataset_path)
@@ -31,6 +42,8 @@ class PCS:
31
42
  token = ANTHROPIC_API_KEY
32
43
  elif annotator_model_name.startswith("mistral") or annotator_model_name.startswith("google"):
33
44
  token = HUGGINGFACE_API_KEY
45
+ else:
46
+ raise ValueError(f"Unsupported annotator model name: {annotator_model_name}")
34
47
 
35
48
  self.annotators.append(Annotator(prompt=self.prompt, labels=self.possible_labels, model_name=annotator_model_name, token=token))
36
49
  self.optimal_llm_weights = [1] * len(self.annotators)
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
 
6
6
  [project]
7
7
  name = "pcs-annotator"
8
- version = "0.1.2"
8
+ version = "0.1.3"
9
9
  authors = [
10
10
  { name = "Sina Salimian", email = "sina99.sn@gmail.com" }
11
11
  ]
@@ -1,24 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pcs-annotator
3
- Version: 0.1.2
4
- Summary: A Python library for classification tasks using multiple LLMs
5
- Project-URL: Homepage, https://github.com/salsina/PCS-Python-Library
6
- Project-URL: Issues, https://github.com/salsina/PCS-Python-Library/issues
7
- Author-email: Sina Salimian <sina99.sn@gmail.com>
8
- License-Expression: MIT
9
- License-File: LICENSE
10
- Classifier: Operating System :: OS Independent
11
- Classifier: Programming Language :: Python :: 3
12
- Requires-Python: >=3.8
13
- Requires-Dist: langchain
14
- Requires-Dist: langchain-anthropic
15
- Requires-Dist: langchain-community
16
- Requires-Dist: langchain-groq
17
- Requires-Dist: langchain-huggingface
18
- Requires-Dist: langchain-openai
19
- Requires-Dist: python-dotenv
20
- Description-Content-Type: text/markdown
21
-
22
- This is a simple example package. You can use
23
- [GitHub-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
24
- to write your content.
@@ -1,3 +0,0 @@
1
- This is a simple example package. You can use
2
- [GitHub-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
3
- to write your content.
File without changes