StyledLines

GPT2-Based Text Stylization Model with Llama.cpp Wrapper in form of a Unity3d Asset Store package avaliable here: https://assetstore.unity.com/packages/slug/292902

This repository provides a GPT2-based text stylization LLM model, wrapped with Llama.cpp to ensure compatibility across various platforms, including iOS and WebGL. The model is designed to transform generic texts into stylized, game or user-tailored dialogue.

purpose of this repo

Please do post issues you find in our docs/code/other stuff here.

Features

Try It Online

Experience the model directly in your browser (with the Q4_K_M model):

Model Usage Example

Provide the following input:

<input> How are you today? <inputEnds>
<style> Pirate's Orwellian and Poetic Question <styleEnds>
<output>

And it will generate:

Hey there, how fares ye today?

Model Information

Recommendations

To get the best results, consider using the following styles:

Tip: Keep your style descriptions short and concise. Combining mood and writing styles often yields the best results.

Integration Notes

The model and code are released under Unity3D Asset Store’s standard End User License Agreement. See the full EULA here.

Coding

Motivating usage example:

using UnityEngine;
using System.Collections;

public class MinimalExample : MonoBehaviour
{
    public BinaryAsset binaryFileAsset;

    private ModelController _llmController = null;
    private void Start()
    {
        _llmController = new ModelController(binaryFileAsset);
        StartCoroutine(GenerateLine());
    }

    private IEnumerator GenerateLine()
    {
        string line = "I love you!";
        string style = "Simple, Confident, Shakespearean";

        var prompt = $"<input> {line} <inputEnds>\\n<style> {style} <styleEnds>\\n<output>";
        var id = _llmController.model.GenerateAsync(prompt);

        while (!_llmController.model.IsGenerationReady(id))
        {
            yield return new WaitForSeconds(0.3f);
        }

        string result = _llmController.model.GetGenerationResults(id);
        result = ModelController.ExtractFirstPart(result, "<out");
        Debug.Log(result); // prints out something like "My heart is boundless with affection!"
    }
}