--- language: - en tags: - text-generation - creative-writing - language-model library_name: transformers pipeline_tag: text-generation --- # Creative Help This is the model repo for Creative Help, a legacy app for AI-based writing assistance powered by a RNN language model. It was developed in 2016 as one of the first demonstrations of the use of a language model for helping people write stories. For more information, see the following research papers: [Automated Assistance for Creative Writing with an RNN Language Model.](https://roemmele.github.io/publications/creative-help-demo.pdf) Melissa Roemmele and Andrew Gordon. Demo at IUI 2018. [Linguistic Features of Helpfulness in Automated Support for Creative Writing.](https://roemmele.github.io/publications/creative-help-evaluation.pdf) Melissa Roemmele and Andrew Gordon. Storytelling Workshop at NAACL 2018. ## Installation ```bash pip install transformers torch python -m spacy download en_core_web_sm ``` ## Loading the Model This model uses a custom implementation of classes in the HF transformers library (this code has been semi-automatically adapted from the original implementation [here](https://github.com/roemmele/narrative-prediction)). If you're loading the model from inside this repo, run: ```python from transformers import AutoConfig, AutoModelForCausalLM from rnnlm_model import ( RNNLMConfig, RNNLMForCausalLM, RNNLMTokenizer, RNNLMTextGenerationPipeline, ) AutoConfig.register("rnnlm", RNNLMConfig) AutoModelForCausalLM.register(RNNLMConfig, RNNLMForCausalLM) model = AutoModelForCausalLM.from_pretrained( "./", trust_remote_code=True, ) tokenizer = RNNLMTokenizer.from_pretrained("./") pipe = RNNLMTextGenerationPipeline(model=model, tokenizer=tokenizer) ``` ## Usage Examples Generation uses a base configuration of `max_new_tokens=50`, `do_sample=True`, and `temperature=1.0` unless overridden. ### Basic Generation (Default Parameters) ```python output = pipe("The storm came", max_new_tokens=50, do_sample=True, temperature=1.0) print(output[0]["generated_text"]) ``` ### Limiting by Sentences (`max_new_sents`) Limit the decoded output to a specific number of sentences: ```python # At most 1 sentence output = pipe( "Sarah closed her laptop and stared out the window.", max_new_tokens=50, max_new_sents=1, ) print(output[0]["generated_text"]) ``` ## Inference API This model is ready to deploy via HF Inference Endpoints. When using the HF Inference API or Inference Endpoints, pass parameters in the request body: ```json { "inputs": "The storm came", "parameters": { "max_new_tokens": 50, "do_sample": true, "temperature": 1.0, "max_new_sents": 2 } } ``` ## Test Script ```bash python test_model.py --model_path . --seed 0 ``` ## Ethical Considerations This model was trained on publically accessible fiction books obtained via the [Toronto BookCorpus](https://yknzhu.wixsite.com/mbweb). There is a known risk that text generated by this model may deemed inappropriate or objectionable.