Enhance Your Text Generation with Activation Additions from ulissemini/gpt2-xl-actadd

21 Apr 2025
Enhance Your Text Generation with Activation Additions from ulissemini/gpt2-xl-actadd

In the ever-evolving realm of natural language processing, the ability to generate coherent and contextually relevant text is paramount. The ulissemini/gpt2-xl-actadd API offers a powerful solution through its Cognitive Action: Generate Text with Activation Additions. This action allows developers to create text sequences that can be fine-tuned through activation modifications, enabling a more nuanced and expressive text generation.

Prerequisites

Before diving into the integration of the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic understanding of JSON and HTTP requests.

Authentication typically involves including your API key in the request headers to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Text with Activation Additions

This action generates text sequences by applying activation modifications using additive and subtractive prompts at a specified network layer. By leveraging probability sampling techniques, developers can produce diverse and coherent outputs tailored to their specific needs.

Input

The input for this action requires the following fields:

  • layer (integer): Specifies the network layer where the activation addition will be applied. (Example: 6)
  • promptAdd (string): Defines the additive component of the activation, typically representing positive or desired attributes. (Example: "Love")
  • promptBatch (array of strings): An array of prompts from which outputs will be generated. (Example: "Did you know that", ...)
  • promptSubtract (string): Defines the subtractive component of the activation, typically representing negative or undesired attributes. (Example: "Hate")
  • seed (integer, optional): Sets the random seed for reproducibility. (Example: 0)
  • coefficient (number, optional): Determines the scalar multiplier applied to the activation addition. (Default: 0, Example: 4)
  • temperature (number, optional): Controls the randomness of sampling in generation. (Default: 1, Example: 1)
  • maxNewTokens (integer, optional): Limits the number of new tokens that can be generated. (Default: 50, Example: 50)
  • topProbability (number, optional): Applies the nucleus sampling technique. (Default: 0.3, Example: 0.3)
  • frequencyPenalty (number, optional): Penalizes the model for generating tokens that already appear in the sequence. (Default: 1, Example: 1)

Here's an example input JSON payload for this action:

{
  "seed": 0,
  "layer": 6,
  "promptAdd": "Love",
  "coefficient": 4,
  "promptBatch": [
    "Did you know that",
    "Did you know that",
    "Did you know that",
    "Did you know that",
    "Did you know that",
    "Did you know that",
    "Did you know that",
    "Did you know that",
    "Did you know that",
    "Did you know that"
  ],
  "temperature": 1,
  "maxNewTokens": 50,
  "promptSubtract": "Hate",
  "topProbability": 0.3,
  "frequencyPenalty": 1
}

Output

Upon execution, the action returns an array of generated text sequences. Here’s a glimpse of the potential outputs you might receive:

[
  "Did you know that I love you too...",
  "Did you know that it's been a long time since I've posted anything here...",
  "Did you know that you can be a part of it...",
  "Did you know that you're always welcome here...",
  "Did you know that you can get more than just a kiss from me...",
  ...
]

These outputs showcase the ability of the action to create coherent and contextually relevant text based on the provided prompts and modifications.

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how you might call the Cognitive Actions execution endpoint:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "73bf0c6f-9ce4-40b1-8303-77439455f514"  # Action ID for Generate Text with Activation Additions

# Construct the input payload based on the action's requirements
payload = {
    "seed": 0,
    "layer": 6,
    "promptAdd": "Love",
    "coefficient": 4,
    "promptBatch": [
        "Did you know that",
        "Did you know that",
        "Did you know that",
        "Did you know that"
    ],
    "temperature": 1,
    "maxNewTokens": 50,
    "promptSubtract": "Hate",
    "topProbability": 0.3,
    "frequencyPenalty": 1
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this example, you would replace the placeholder for your Cognitive Actions API key and use the hypothetical endpoint URL for the API. The payload is structured according to the action's requirements, ensuring that all necessary fields are included.

Conclusion

The Generate Text with Activation Additions action from the ulissemini/gpt2-xl-actadd API empowers developers to create rich, context-aware text generation capabilities in their applications. By utilizing activation modifications, you can enhance the expressiveness and diversity of the generated outputs.

Experiment with different prompts and parameters to discover the full potential of this powerful text generation tool!