### Install GGUF with CPU Support Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Install scikit-llm with GGUF support for CPU-only environments. This command ensures the necessary llama-cpp-python bindings are installed. ```bash pip install scikit-llm[gguf] --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu --no-cache-dir ``` -------------------------------- ### Train and Predict with GPTClassifier Source: https://skllm.beastbyte.ai/docs/tunable-text-classification Example demonstrating how to initialize, train, and predict using the GPTClassifier. Ensure you have the necessary data loaded into X and y. ```python from skllm.models.gpt.classification.tunable import GPTClassifier X, y = get_classification_dataset() clf = GPTClassifier(n_epochs=1) clf.fit(X,y) clf.predict(X) ``` -------------------------------- ### Initialize and Fit DynamicFewShotGPTClassifier Source: https://skllm.beastbyte.ai/docs/dynamic-few-shot-text-classification Initialize the DynamicFewShotGPTClassifier with a specified number of examples per class and fit it to the training data. This prepares the classifier for making predictions using dynamic few-shot learning. ```python from skllm.models.gpt.classification.few_shot import DynamicFewShotGPTClassifier query = "I have fallen deeply in love with this sci-fi book; its unique blend of science and fiction has me spellbound." clf = DynamicFewShotGPTClassifier(n_examples=1).fit(X,y) prompt = clf._get_prompt(query) print(prompt) ``` -------------------------------- ### Sentiment Analysis Tagging Example Source: https://skllm.beastbyte.ai/docs/tagging-overview Demonstrates how raw text can be transformed into tagged output for sentiment analysis. This example shows the input text and its corresponding tagged output. ```text Input: ``` I love my new phone, but I am disappointed with the battery life. ``` Output: ``` I love my new phone, but I am disappointed with the battery life. ``` ``` -------------------------------- ### Install GGUF with Metal GPU Support (MacOS) Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Install scikit-llm with GGUF support for GPU acceleration on MacOS using Metal. This is specifically for M-series Macs. ```bash pip install scikit-llm[gguf] --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal --no-cache-dir ``` -------------------------------- ### Few-Shot Text Classification Example Source: https://skllm.beastbyte.ai/docs/few-shot-text-classification Demonstrates single-label and multi-label few-shot text classification using GPT-4. Ensure you have the necessary datasets loaded. ```python from skllm.models.gpt.classification.few_shot import ( FewShotGPTClassifier, MultiLabelFewShotGPTClassifier, ) from skllm.datasets import ( get_classification_dataset, get_multilabel_classification_dataset, ) # single label X, y = get_classification_dataset() clf = FewShotGPTClassifier(model="gpt-4o") clf.fit(X,y) labels = clf.predict(X) # multi-label X, y = get_multilabel_classification_dataset() clf = MultiLabelFewShotGPTClassifier(max_labels=2, model="gpt-4o") clf.fit(X,y) labels = clf.predict(X) ``` -------------------------------- ### Install GGUF with CUDA GPU Support Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Install scikit-llm with GGUF support for GPU acceleration using CUDA 12.1 or later. This command specifies the appropriate extra index URL for CUDA bindings. ```bash pip install scikit-llm[gguf] --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121 --no-cache-dir ``` -------------------------------- ### DynamicFewShotGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/dynamic-few-shot-text-classification Initializes the DynamicFewShotGPTClassifier with specified parameters. This class is designed for dynamic few-shot text classification, adapting to larger datasets by constructing dynamic subsets of examples for each sample. ```APIDOC ## DynamicFewShotGPTClassifier Initializes the dynamic few-shot text classification model. ### Parameters - **model** (str) - Optional - Model to use, by default "gpt-3.5-turbo". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **n_examples** (int) - Optional - Number of closest examples per class to be retrieved, by default 3. - **memory_index** (Optional[IndexConstructor]) - Optional - Custom memory index, for details check `skllm.memory` submodule, by default None. - **vectorizer** (Optional[BaseVectorizer]) - Optional - Scikit-LLM vectorizer; if None, `GPTVectorizer` is used, by default None. - **metric** (Optional[str]) - Optional - Metric used for similarity search by the memory_index, by default "euclidean" ``` -------------------------------- ### Define Training Data for Text Classification Source: https://skllm.beastbyte.ai/docs/dynamic-few-shot-text-classification Define the input text samples (X) and their corresponding labels (y) for a text classification task. This example sets up data for classifying reviews as 'books' or 'movies'. ```python X = [ "I love reading science fiction novels, they transport me to other worlds.", # example 1 - book - sci-fi "A good mystery novel keeps me guessing until the very end.", # example 2 - book - mystery "Historical novels give me a sense of different times and places.", # example 3 - book - historical "I love watching science fiction movies, they transport me to other galaxies.", # example 4 - movie - sci-fi "A good mystery movie keeps me on the edge of my seat.", # example 5 - movie - mystery "Historical movies offer a glimpse into the past.", # example 6 - movie - historical ] y = ["books", "books", "books", "movies", "movies", "movies"] ``` -------------------------------- ### FewShotGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/few-shot-text-classification Initializes the FewShotGPTClassifier for single-label text classification. This class uses a few examples to classify new text into predefined classes. ```APIDOC ## FewShotGPTClassifier ### Description Initializes the FewShotGPTClassifier for single-label text classification. This class uses a few examples to classify new text into predefined classes. ### Parameters #### Initialization Parameters - **model** (str) - Optional - Model to use, by default "gpt-3.5-turbo". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. ### Usage Example ```python from skllm.models.gpt.classification.few_shot import FewShotGPTClassifier clf = FewShotGPTClassifier(model="gpt-4o") ``` ``` -------------------------------- ### Initialize GPTVectorizer Source: https://skllm.beastbyte.ai/docs/text-vectorization Import and initialize the GPTVectorizer. This snippet shows the basic import statement for the class. ```python from skllm.models.gpt.vectorization import GPTVectorizer ``` -------------------------------- ### Initialize and Use GPTExplainableNER Source: https://skllm.beastbyte.ai/docs/ner Demonstrates initializing the GPTExplainableNER model with custom entities and transforming sample data to tag named entities. The `display_predictions` parameter is set to True for human-readable output. ```python from skllm.models.gpt.tagging.ner import GPTExplainableNER as NER entities = { "PERSON": "A name of an individual.", "ORGANIZATION": "A name of a company.", "DATE": "A specific time reference." } data = [ "Tim Cook announced new Apple products in San Francisco on June 3, 2022.", "Elon Musk visited the Tesla factory in Austin on January 10, 2021.", "Mark Zuckerberg introduced Facebook Metaverse in Silicon Valley on May 5, 2023." ] ner = NER(entities=entities, display_predictions=True) tagged = ner.fit_transform(data) ``` -------------------------------- ### TunableGPTText2Text Initialization Source: https://skllm.beastbyte.ai/docs/tunable-text-to-text Initializes a tunable GPT text-to-text estimator. This model can be tuned for various tasks using provided data without additional preprocessing. The `fit` method trains the model, and `transform` generates output. ```APIDOC ## TunableGPTText2Text ### Description Initializes a tunable GPT text-to-text estimator. This model can be tuned for various tasks using provided data without additional preprocessing. The `fit` method trains the model, and `transform` generates output. ### Parameters #### Initialization Parameters - **base_model** (str) - Model to use, by default "gpt-3.5-turbo-0613". - **key** (Optional[str]) - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Estimator-specific ORG key; if None, retrieved from the global config, by default None. - **n_epochs** (Optional[int]) - Number of epochs; if None, determined automatically; by default None. - **custom_suffix** (Optional[str]) - Custom suffix of the tuned model, used for naming purposes only, by default "skllm". ### Example Usage ```python from skllm.models.gpt.text2text.tunable import TunableGPTText2Text model = TunableGPTText2Text( base_model = "gpt-3.5-turbo-0613", n_epochs = None, system_msg = "You are a text processing model." ) model.fit(X_train, y_train) # y_train is any desired output text out = model.transform(X_test) ``` ``` -------------------------------- ### Initialize and Train TunableGPTText2Text Model Source: https://skllm.beastbyte.ai/docs/tunable-text-to-text Demonstrates how to initialize a TunableGPTText2Text model with a specified base model and system message, then train it using provided data. The y_train parameter should contain the desired output text. ```python from skllm.models.gpt.text2text.tunable import TunableGPTText2Text model = TunableGPTText2Text( base_model = "gpt-3.5-turbo-0613", n_epochs = None, # int or None. When None, will be determined automatically by OpenAI system_msg = "You are a text processing model." ) model.fit(X_train, y_train) # y_train is any desired output text out = model.transform(X_test) ``` -------------------------------- ### TunableVertexText2Text Initialization Source: https://skllm.beastbyte.ai/docs/tunable-text-to-text Initializes a tunable Vertex AI text-to-text estimator. This model can be tuned for various tasks using provided data without additional preprocessing. The `fit` method trains the model, and `transform` generates output. ```APIDOC ## TunableVertexText2Text ### Description Initializes a tunable Vertex AI text-to-text estimator. This model can be tuned for various tasks using provided data without additional preprocessing. The `fit` method trains the model, and `transform` generates output. ### Parameters #### Initialization Parameters - **base_model** (str) - Model to use, by default "text-bison@002". - **n_update_steps** (int) - Number of epochs, by default 1. ### Example Usage ```python from skllm.models.vertex.text2text.tunable import TunableVertexText2Text # Example initialization (actual usage may vary based on skllm's API) # model = TunableVertexText2Text(base_model="text-bison@002", n_update_steps=5) ``` ``` -------------------------------- ### Initialize MultiLabelZeroShotVertexClassifier Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Import and initialize the MultiLabelZeroShotVertexClassifier. This model supports multi-label zero-shot classification using Vertex AI. ```python from skllm.models.vertex.classification.zero_shot import MultiLabelZeroShotVertexClassifier ``` -------------------------------- ### Initialize ZeroShotVertexClassifier Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Import and initialize the ZeroShotVertexClassifier. This model leverages Vertex AI for zero-shot classification. ```python from skllm.models.vertex.classification.zero_shot import ZeroShotVertexClassifier ``` -------------------------------- ### GPTExplainableNER Initialization Source: https://skllm.beastbyte.ai/docs/ner This snippet shows how to initialize the GPTExplainableNER estimator with various parameters. The estimator can recognize specified entities, control prediction display, choose between sparse or dense output, select a GPT model, and configure API keys and worker threads. ```APIDOC ## GPTExplainableNER ### Description Initializes the GPTExplainableNER estimator for Named Entity Recognition. ### Parameters #### Initialization Parameters - **entities** (dict) - Required - A dictionary of entities to recognize, with keys as **uppercase** entity names and values as descriptions. - **display_predictions** (Optional[bool]) - Optional - Determines whether to display predictions, by default False. - **sparse_output** (Optional[bool]) - Optional - Determines whether to generate a sparse representation of the predictions, by default True. - **model** (Optional[str]) - Optional - A model to use, by default "gpt-4o". - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. - **num_workers** (Optional[int]) - Optional - Number of workers (threads) to use, by default 1. ``` -------------------------------- ### DynamicFewShotGPTClassifier Initialization Parameters Source: https://skllm.beastbyte.ai/docs/dynamic-few-shot-text-classification Illustrates the import statement for the DynamicFewShotGPTClassifier. This is typically used to initialize the classifier with various parameters for customization. ```python from skllm.models.gpt.classification.few_shot import DynamicFewShotGPTClassifier ``` -------------------------------- ### Import TunableGPTText2Text Source: https://skllm.beastbyte.ai/docs/tunable-text-to-text Shows the import statement required to use the TunableGPTText2Text estimator from the skllm library. ```python from skllm.models.gpt.text2text.tunable import TunableGPTText2Text ``` -------------------------------- ### Initialize MultiLabelZeroShotGPTClassifier Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Import and initialize the MultiLabelZeroShotGPTClassifier. This model supports multi-label zero-shot classification using GPT. ```python from skllm.models.gpt.classification.zero_shot import MultiLabelZeroShotGPTClassifier ``` -------------------------------- ### GPTVectorizer Initialization Source: https://skllm.beastbyte.ai/docs/text-vectorization Initializes the GPTVectorizer for text embedding. It allows customization of the model, batch size, and API keys. ```APIDOC ## GPTVectorizer ### Description Initializes the GPTVectorizer for text embedding. It allows customization of the model, batch size, and API keys. ### Parameters #### Initialization Parameters - **model** (str) - Optional - Model to use, by default "text-embedding-3-small". - **batch_size** (int) - Optional - Number of samples per request, by default 1. - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. ### Usage Example ```python from skllm.models.gpt.vectorization import GPTVectorizer vectorizer = GPTVectorizer(batch_size=2, model="text-embedding-ada-002") X = vectorizer.fit_transform(["This is a text", "This is another text"]) ``` ``` -------------------------------- ### Initialize ZeroShotGPTClassifier Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Import and initialize the ZeroShotGPTClassifier. This model uses GPT for zero-shot classification. ```python from skllm.models.gpt.classification.zero_shot import ZeroShotGPTClassifier ``` -------------------------------- ### Import TunableVertexText2Text Source: https://skllm.beastbyte.ai/docs/tunable-text-to-text Shows the import statement required to use the TunableVertexText2Text estimator from the skllm library. ```python from skllm.models.vertex.text2text.tunable import TunableVertexText2Text ``` -------------------------------- ### GPTSummarizer Initialization Source: https://skllm.beastbyte.ai/docs/text-summarization Initializes the GPTSummarizer with specified parameters for text summarization. The remaining methods follow the syntax of a scikit-learn transformer. ```APIDOC ## GPTSummarizer ### Description Initializes the GPTSummarizer for text summarization tasks. ### Parameters #### Initialization Parameters - **model** (str) - Model to use, by default "gpt-3.5-turbo". - **key** (Optional[str]) - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Estimator-specific ORG key; if None, retrieved from the global config, by default None. - **max_words** (int) - Soft limit of the summary length, by default 15. - **focus** (Optional[str]) - Concept in the text to focus on, by default None. ``` -------------------------------- ### Initialize and Use CoTGPTClassifier for Sentiment Analysis Source: https://skllm.beastbyte.ai/docs/chain-of-thought-text-classification Demonstrates initializing CoTGPTClassifier with GPT-4o, fitting it to a dataset, and making predictions that include both labels and reasoning. ```python from skllm.models.gpt.classification.zero_shot import CoTGPTClassifier from skllm.datasets import get_classification_dataset # demo sentiment analysis dataset # labels: positive, negative, neutral X, y = get_classification_dataset() clf = CoTGPTClassifier(model="gpt-4o") clf.fit(X,y) predictions = clf.predict(X) labels, reasoning = predictions[:, 0], predictions[:, 1] ``` -------------------------------- ### Import GPTExplainableNER Source: https://skllm.beastbyte.ai/docs/ner Shows the import statement for the GPTExplainableNER class from the Scikit-LLM library. ```python from skllm.models.gpt.tagging.ner import GPTExplainableNER ``` -------------------------------- ### Embed Text using GPTVectorizer Source: https://skllm.beastbyte.ai/docs/text-vectorization Use GPTVectorizer to convert text into fixed-dimensional vectors. Initialize with a batch size and then use fit_transform. ```python from skllm.models.gpt.vectorization import GPTVectorizer vectorizer = GPTVectorizer(batch_size=2) X = vectorizer.fit_transform(["This is a text", "This is another text"]) ``` -------------------------------- ### MultiLabelFewShotGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/few-shot-text-classification Import and initialize the `MultiLabelFewShotGPTClassifier`. This classifier is designed for multi-label text classification tasks. ```python from skllm.models.gpt.classification.few_shot import MultiLabelFewShotGPTClassifier ``` -------------------------------- ### Configure Custom URL Backend Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Set a global custom URL for using any OpenAI-compatible provider with Scikit-LLM. This is useful for local or cloud-hosted models. ```python from skllm.config import SKLLMConfig SKLLMConfig.set_gpt_url("http://localhost:8000/") clf = ZeroShotGPTClassifier(model="custom_url::") ``` -------------------------------- ### CoTGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/chain-of-thought-text-classification This section details the parameters required for initializing the CoTGPTClassifier. The class follows the standard scikit-learn classifier syntax for other methods. ```APIDOC ## CoTGPTClassifier ### Description Initializes the Chain-of-Thought GPT Classifier. ### Parameters #### Initialization Parameters - **model** (str) - Required - Model to use, by default "gpt-3.5-turbo". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. ### Usage ```python from skllm.models.gpt.classification.zero_shot import CoTGPTClassifier clf = CoTGPTClassifier(model="gpt-4o", default_label="positive") ``` ``` -------------------------------- ### FewShotGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/few-shot-text-classification Import and initialize the `FewShotGPTClassifier`. This classifier is suitable for single-label text classification tasks. ```python from skllm.models.gpt.classification.few_shot import FewShotGPTClassifier ``` -------------------------------- ### Import CoTGPTClassifier Source: https://skllm.beastbyte.ai/docs/chain-of-thought-text-classification Shows the import statement for the CoTGPTClassifier class from the SKLLM library. ```python from skllm.models.gpt.classification.zero_shot import CoTGPTClassifier ``` -------------------------------- ### Basic Text Summarization Source: https://skllm.beastbyte.ai/docs/text-summarization Use this snippet to perform basic text summarization on a dataset. It initializes the GPTSummarizer and transforms the input data. ```python from skllm.models.gpt.text2text.summarization import GPTSummarizer from skllm.datasets import get_summarization_dataset X = get_summarization_dataset() summarizer = GPTSummarizer(model="gpt-3.5-turbo", max_words=15) X_summarized = summarizer.fit_transform(X) ``` -------------------------------- ### MultiLabelZeroShotVertexClassifier Initialization Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Initializes the MultiLabelZeroShotVertexClassifier with specified parameters. This model supports multi-label zero-shot text classification using Vertex AI. ```APIDOC ## MultiLabelZeroShotVertexClassifier ### Description Initializes the MultiLabelZeroShotVertexClassifier with specified parameters. This model supports multi-label zero-shot text classification using Vertex AI. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **model** (str) - Optional - Model to use, by default "text-bison@002". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **max_labels** (Optional[int]) - Optional - Maximum labels per sample, by default 5. - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. ### Request Example ```json { "model": "text-bison@002", "default_label": "Random", "max_labels": 5, "prompt_template": null } ``` ### Response #### Success Response (200) Initializes the classifier object. #### Response Example ```json { "message": "Classifier initialized successfully" } ``` ``` -------------------------------- ### ZeroShotVertexClassifier Initialization Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Initializes the ZeroShotVertexClassifier with specified parameters. This model is designed for zero-shot text classification using Vertex AI. ```APIDOC ## ZeroShotVertexClassifier ### Description Initializes the ZeroShotVertexClassifier with specified parameters. This model is designed for zero-shot text classification using Vertex AI. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **model** (str) - Optional - Model to use, by default "text-bison@002". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. ### Request Example ```json { "model": "text-bison@002", "default_label": "Random", "prompt_template": null } ``` ### Response #### Success Response (200) Initializes the classifier object. #### Response Example ```json { "message": "Classifier initialized successfully" } ``` ``` -------------------------------- ### GPTTranslator Initialization Source: https://skllm.beastbyte.ai/docs/text-translation This section details the parameters required for initializing the GPTTranslator estimator. The remaining methods follow the standard scikit-learn transformer syntax. ```APIDOC ## GPTTranslator ### Description Initializes the GPTTranslator for text translation tasks. ### Parameters #### Initialization Parameters - **model** (str) - Optional - Model to use, by default "gpt-3.5-turbo". - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. - **output_language** (str) - Required - Target language, by default "English". ``` -------------------------------- ### Authenticate Google Cloud for Vertex AI Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Log in to Google Cloud to set application default credentials for using the Vertex AI backend. This command is run via the Google Cloud CLI. ```bash gcloud auth application-default login ``` -------------------------------- ### MultiLabelZeroShotGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Initializes the MultiLabelZeroShotGPTClassifier with specified parameters. This model supports multi-label zero-shot text classification using GPT. ```APIDOC ## MultiLabelZeroShotGPTClassifier ### Description Initializes the MultiLabelZeroShotGPTClassifier with specified parameters. This model supports multi-label zero-shot text classification using GPT. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **model** (str) - Optional - Model to use, by default "gpt-3.5-turbo". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **max_labels** (Optional[int]) - Optional - Maximum labels per sample, by default 5. - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. ### Request Example ```json { "model": "gpt-3.5-turbo", "default_label": "Random", "max_labels": 5, "prompt_template": null, "key": null, "org": null } ``` ### Response #### Success Response (200) Initializes the classifier object. #### Response Example ```json { "message": "Classifier initialized successfully" } ``` ``` -------------------------------- ### ZeroShotGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Initializes the ZeroShotGPTClassifier with specified parameters. This model is designed for zero-shot text classification using GPT. ```APIDOC ## ZeroShotGPTClassifier ### Description Initializes the ZeroShotGPTClassifier with specified parameters. This model is designed for zero-shot text classification using GPT. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **model** (str) - Optional - Model to use, by default "gpt-3.5-turbo". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. ### Request Example ```json { "model": "gpt-3.5-turbo", "default_label": "Random", "prompt_template": null, "key": null, "org": null } ``` ### Response #### Success Response (200) Initializes the classifier object. #### Response Example ```json { "message": "Classifier initialized successfully" } ``` ``` -------------------------------- ### MultiLabelGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/tunable-text-classification Initializes a MultiLabelGPTClassifier for tunable multi-label text classification. This class allows fine-tuning of GPT models for multi-label classification tasks. The remaining methods follow scikit-learn classifier syntax. ```APIDOC ## MultiLabelGPTClassifier ### Description Initializes a MultiLabelGPTClassifier for tunable multi-label text classification. This class allows fine-tuning of GPT models for multi-label classification tasks. The remaining methods follow scikit-learn classifier syntax. ### Parameters #### Initialization Parameters - **base_model** (str) - Optional - Base model to use, by default "gpt-3.5-turbo-0613". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. - **n_epochs** (Optional[int]) - Optional - Number of epochs; if None, determined automatically; by default None. - **custom_suffix** (Optional[str]) - Optional - Custom suffix of the tuned model, used for naming purposes only, by default "skllm". - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. - **max_labels** (Optional[int]) - Optional - Maximum labels per sample, by default 5. ``` -------------------------------- ### VertexClassifier Initialization Source: https://skllm.beastbyte.ai/docs/tunable-text-classification Initializes a VertexClassifier for tunable text classification using Vertex AI models. This class allows fine-tuning of Vertex AI models for classification tasks. The remaining methods follow scikit-learn classifier syntax. ```APIDOC ## VertexClassifier ### Description Initializes a VertexClassifier for tunable text classification using Vertex AI models. This class allows fine-tuning of Vertex AI models for classification tasks. The remaining methods follow scikit-learn classifier syntax. ### Parameters #### Initialization Parameters - **base_model** (str) - Optional - Base model to use, by default "text-bison@002". - **n_update_steps** (int) - Optional - Number of epochs, by default 1. - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". ``` -------------------------------- ### Import GPTTranslator Class Source: https://skllm.beastbyte.ai/docs/text-translation Import the GPTTranslator class for text translation tasks. This is a prerequisite for initializing the translator. ```python from skllm.models.gpt.text2text.translation import GPTTranslator ``` -------------------------------- ### Configure Google Project ID for Vertex AI Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Set your Google Cloud project ID to configure Scikit-LLM for the Vertex AI backend. This is a necessary step after authenticating. ```python from skllm.config import SKLLMConfig SKLLMConfig.set_google_project("") ``` -------------------------------- ### Set OpenAI API Key and Organization ID Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Configure your OpenAI API key and organization ID to use the default OpenAI backend. Ensure these are set before making any API calls. ```python from skllm.config import SKLLMConfig SKLLMConfig.set_openai_key("") SKLLMConfig.set_openai_org("") ``` -------------------------------- ### Combine GPTVectorizer with XGBoost in a Pipeline Source: https://skllm.beastbyte.ai/docs/text-vectorization Integrate GPTVectorizer into a scikit-learn pipeline with an XGBoost classifier for end-to-end text classification. Ensure labels are encoded before fitting. ```python from sklearn.pipeline import Pipeline from sklearn.preprocessing import LabelEncoder from xgboost import XGBClassifier le = LabelEncoder() y_train_encoded = le.fit_transform(y_train) y_test_encoded = le.transform(y_test) steps = [("GPT", GPTVectorizer()), ("Clf", XGBClassifier())] clf = Pipeline(steps) clf.fit(X_train, y_train_encoded) yh = clf.predict(X_test) ``` -------------------------------- ### Text Summarization with Focus Source: https://skllm.beastbyte.ai/docs/text-summarization This snippet demonstrates how to generate a summary that emphasizes a specific concept by using the `focus` parameter. The `max_words` parameter sets a soft limit on the summary length. ```python summarizer = GPTSummarizer(model="gpt-3.5-turbo", max_words=15, focus="apples") ``` -------------------------------- ### GPTSummarizer Import Source: https://skllm.beastbyte.ai/docs/text-summarization This code imports the GPTSummarizer class, which is the primary tool for text summarization in this library. ```python from skllm.models.gpt.text2text.summarization import GPTSummarizer ``` -------------------------------- ### Import MultiLabelGPTClassifier Source: https://skllm.beastbyte.ai/docs/tunable-text-classification Import statement for the MultiLabelGPTClassifier. Use this when dealing with multi-label classification tasks. ```python from skllm.models.gpt.classification.tunable import MultiLabelGPTClassifier ``` -------------------------------- ### MultiLabelFewShotGPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/few-shot-text-classification Initializes the MultiLabelFewShotGPTClassifier for multi-label text classification. This class handles scenarios where a text can belong to multiple classes simultaneously. ```APIDOC ## MultiLabelFewShotGPTClassifier ### Description Initializes the MultiLabelFewShotGPTClassifier for multi-label text classification. This class handles scenarios where a text can belong to multiple classes simultaneously. ### Parameters #### Initialization Parameters - **model** (str) - Optional - Model to use, by default "gpt-3.5-turbo". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **max_labels** (Optional[int]) - Optional - Maximum labels per sample, by default 5. - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. ### Usage Example ```python from skllm.models.gpt.classification.few_shot import MultiLabelFewShotGPTClassifier clf = MultiLabelFewShotGPTClassifier(max_labels=2, model="gpt-4o") ``` ``` -------------------------------- ### Set Maximum GPU Layers for GGUF Models Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Configure the maximum number of GGUF model layers to offload to the GPU. Use -1 to offload all layers, 0 for all layers on CPU, or a positive integer for a specific number of layers on the GPU. ```python from skllm.config import SKLLMConfig SKLLMConfig.set_gguf_max_gpu_layers(-1) ``` -------------------------------- ### Import VertexClassifier Source: https://skllm.beastbyte.ai/docs/tunable-text-classification Import statement for the VertexClassifier. This is used for text classification tasks leveraging Vertex AI models. ```python from skllm.models.vertex.classification.tunable import VertexClassifier ``` -------------------------------- ### GPTClassifier Initialization Source: https://skllm.beastbyte.ai/docs/tunable-text-classification Initializes a GPTClassifier for tunable text classification. This class allows fine-tuning of GPT models for classification tasks. The remaining methods follow scikit-learn classifier syntax. ```APIDOC ## GPTClassifier ### Description Initializes a GPTClassifier for tunable text classification. This class allows fine-tuning of GPT models for classification tasks. The remaining methods follow scikit-learn classifier syntax. ### Parameters #### Initialization Parameters - **base_model** (str) - Optional - Base model to use, by default "gpt-3.5-turbo-0613". - **default_label** (str) - Optional - Default label for failed prediction; if "Random" -> selects randomly based on class frequencies, by default "Random". - **key** (Optional[str]) - Optional - Estimator-specific API key; if None, retrieved from the global config, by default None. - **org** (Optional[str]) - Optional - Estimator-specific ORG key; if None, retrieved from the global config, by default None. - **n_epochs** (Optional[int]) - Optional - Number of epochs; if None, determined automatically; by default None. - **custom_suffix** (Optional[str]) - Optional - Custom suffix of the tuned model, used for naming purposes only, by default "skllm". - **prompt_template** (Optional[str]) - Optional - Custom prompt template to use, by default None. ``` -------------------------------- ### Set Azure OpenAI API Key and Base URL Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Configure your Azure API key and endpoint to use the Azure OpenAI service. The endpoint is typically found under 'Keys and Endpoint' in your Azure resource management. ```python from skllm.config import SKLLMConfig # Found under: Resource Management (Left Sidebar) -> Keys and Endpoint -> KEY 1 SKLLMConfig.set_gpt_key("") # Found under: Resource Management (Left Sidebar) -> Keys and Endpoint -> Endpoint SKLLMConfig.set_azure_api_base("") # e.g. https://.openai.azure.com/ ``` -------------------------------- ### Translate Text using GPTTranslator Source: https://skllm.beastbyte.ai/docs/text-translation Translate a dataset to English using the GPTTranslator. Ensure you have the necessary models and datasets available. ```python from skllm.models.gpt.text2text.translation import GPTTranslator from skllm.datasets import get_translation_dataset X = get_translation_dataset() t = GPTTranslator(model="gpt-3.5-turbo", output_language="English") translated_text = t.fit_transform(X) ``` -------------------------------- ### Import GPTClassifier Source: https://skllm.beastbyte.ai/docs/tunable-text-classification Import statement for the GPTClassifier. This is typically used at the beginning of your script. ```python from skllm.models.gpt.classification.tunable import GPTClassifier ``` -------------------------------- ### Zero-Shot Classification Without Training Data Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Perform zero-shot classification by manually providing candidate labels when no training data is available. Uses a sentiment analysis dataset. ```python from skllm.models.gpt.classification.zero_shot import ZeroShotGPTClassifier from skllm.datasets import get_classification_dataset X, _ = get_classification_dataset() clf = ZeroShotGPTClassifier() clf.fit(None, ["positive", "negative", "neutral"]) labels = clf.predict(X) ``` -------------------------------- ### Zero-Shot Classification with Training Data Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Classify text using ZeroShotGPTClassifier when training data is available to extract candidate labels. Uses a sentiment analysis dataset. ```python from skllm.models.gpt.classification.zero_shot import ZeroShotGPTClassifier from skllm.datasets import get_classification_dataset # demo sentiment analysis dataset # labels: positive, negative, neutral X, y = get_classification_dataset() clf = ZeroShotGPTClassifier(model="gpt-3.5-turbo") clf.fit(X,y) labels = clf.predict(X) ``` -------------------------------- ### Multi-Label Zero-Shot Classification Source: https://skllm.beastbyte.ai/docs/zero-shot-text-classification Classify text into multiple labels simultaneously using MultiLabelZeroShotGPTClassifier. Requires a list of candidate labels and specifies the maximum number of labels to assign. ```python from skllm.models.gpt.classification.zero_shot import MultiLabelZeroShotGPTClassifier from skllm.datasets import get_multilabel_classification_dataset X, _ = get_multilabel_classification_dataset() candidate_labels = [ "Quality", "Price", "Delivery", "Service", "Product Variety", "Customer Support", "Packaging", "User Experience", "Return Policy", "Product Information", ] clf = MultiLabelZeroShotGPTClassifier(max_labels=3) clf.fit(None, [candidate_labels]) labels = clf.predict(X) ``` -------------------------------- ### Clear GGUF Model Cache Source: https://skllm.beastbyte.ai/docs/introduction-backend-families Clear the GGUF model cache to free up memory. This is useful when switching between models or in interactive environments like Jupyter notebooks. ```python from skllm.llm.gpt.clients.llama_cpp.handler import ModelCache ModelCache.clear() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.