<jupyter_start><jupyter_text>Few-shot Learning with GPT-J> API details.<jupyter_code># export
import os
import pandas as pd
#hide
from nbdev.showdoc import *
import toml
s = toml.load("../.streamlit/secrets.toml", _dict=dict)<jupyter_output><empty_output><jupyter_text>Using `GPT_J` model API from [Nlpcloud](https://nlpcloud.io/home/token)<jupyter_code>import nlpcloud
client = nlpcloud.Client("gpt-j", s['nlpcloud_token'], gpu=True)<jupyter_output><empty_output><jupyter_text>![image.png](attachment:image.png)  Aoe2 Civ Builderhttps://ageofempires.fandom.com/wiki/Civilizations_(Age_of_Empires_II)<jupyter_code># example API call
generation = client.generation("""Civilisation: Britons
Specialty: Foot archers
Unique unit: Longbowman
Unique technologies: Yeomen (+1 range for foot archers and +2 attack for towers)
Unique technologies: Warwolf (Trebuchets do blast damage)
Wonder: Chichester Cathedral
Civilization bonuses: Shepherds work 25% faster.
Team bonus: Town Centers cost -50% wood (starting in the Castle Age).
###
Civilisation: Mongols
Specialty: Cavalry archers
Unique unit:  Mangudai
Unique technologies: Nomads (Houses retain population when destroyed)
Unique technologies: Drill (Siege Workshop units move 50% faster)
Wonder: Great Tent of Genghis Khan
Civilization bonuses: Hunters work 40% faster.
Team bonus: The Scout Cavalry line has +2 Line of Sight.
###     
Civilisation: Celts
Specialty: Infantry and siege weapons
Unique unit: Woad Raider
Unique technologies: Stronghold (Castles and towers fire 25% faster)
Unique technologies: Furor Celtica (Siege Workshop units have +40% HP)
Wonder: Rock of Cashel
Civilization bonuses: Infantry units move 15% faster (starting in the Feudal Age).
Civilization bonuses: Lumberjacks work 15% faster.
Civilization bonuses: Siege weapons fire 25% faster.
Civilization bonuses: Enemy herdables can be converted regardless of enemy units next to them.
Team bonus: Siege Workshops work 20% faster.
###
Civilisation: New Zealand Maori""",
    max_length=250,
    length_no_input=True,
    end_sequence="###",
    remove_input=True)

print('Civilisation: New Zealand Maori\n ', generation["generated_text"])

def create_input_string(civname):
    return f"""Civilisation: Britons
Specialty: Foot archers
Unique unit: Longbowman
Unique technologies: Yeomen (+1 range for foot archers and +2 attack for towers)
Unique technologies: Warwolf (Trebuchets do blast damage)
Wonder: Chichester Cathedral
Civilization bonuses: Shepherds work 25% faster.
Team bonus: Town Centers cost -50% wood (starting in the Castle Age).
###
Civilisation: Mongols
Specialty: Cavalry archers
Unique unit:  Mangudai
Unique technologies: Nomads (Houses retain population when destroyed)
Unique technologies: Drill (Siege Workshop units move 50% faster)
Wonder: Great Tent of Genghis Khan
Civilization bonuses: Hunters work 40% faster.
Team bonus: The Scout Cavalry line has +2 Line of Sight.
###     
Civilisation: Celts
Specialty: Infantry and siege weapons
Unique unit: Woad Raider
Unique technologies: Stronghold (Castles and towers fire 25% faster)
Unique technologies: Furor Celtica (Siege Workshop units have +40% HP)
Wonder: Rock of Cashel
Civilization bonuses: Infantry units move 15% faster (starting in the Feudal Age).
Civilization bonuses: Lumberjacks work 15% faster.
Civilization bonuses: Siege weapons fire 25% faster.
Civilization bonuses: Enemy herdables can be converted regardless of enemy units next to them.
Team bonus: Siege Workshops work 20% faster.
###
Civilisation: {civname}"""


def generate_civ(civname, client):
    """
    Creates input string and sends to nlpcloud for few-shot learning
    """
    print(f'🌐 Generating New Civ: {civname} \n')

    input_str = create_input_string(civname)

    generation = client.generation(input_str,
                max_length=250,
                length_no_input=True,
                end_sequence='###',
                remove_input=True)
    civgen = generation["generated_text"].strip('\n')
    
    print(f"🛡️ **{civname}**\n{civgen}")
    
    return civgen

c = generate_civ(civname='New Zealand Maori', client=client)
c = generate_civ(civname='Fijians', client=client)<jupyter_output>🌐 Generating New Civ: Fijians 

🛡️ **Fijians**
Specialty: Specialized attack, long range combat, and shipbuilding
Unique unit: War canoe
Unique technologies: War canoes (+2 attack, +20% range), Shipwrights (+70% build ship time)
Wonder: Tanna or Makatea Islands
Civilization bonuses:  Taino can fight from land and sea.  Taino can build shipwrights at +70% of normal rate.
Team bonus:  Taino build shipwrights at +75% of normal rate. - +10% of time at sea to build ships.
###<jupyter_text>![image.png](attachment:image.png)<jupyter_code>c = generate_civ(civname='Canadians', client=client)
c = generate_civ(civname='European Union', client=client)
c = generate_civ(civname='Dutch', client=client)
c = generate_civ(civname='Star Wars Death Star', client=client)<jupyter_output>🌐 Generating New Civ: Star Wars Death Star 

🛡️ **Star Wars Death Star**
Specialty:  Rocket launchers and star destroyers
Unique unit: Heavy weapons teams
Unique technologies: Trench defenses (Rocket turrets have +40% HP)
Unique technologies: Heavy weapons teams (Rocket turrets and star destroyers fire 75% faster)
Wonder: X-Wing starfighters
Civilization bonuses: Heavy weapons teams have +10% Accuracy.
#Civilization: Wurrrgh
Specialty:  The space dog.
Unique unit: Wurrrrh
Hoardable: Wurrrh (The space dog always has a horde of space hamsters with it.)
Units: Space hamsters
Team bonus: Space hamsters are 10% more accurate for all attacks.
Specialist: Space hamsters
###
{'fraction_non_alphanumeric': 0.0886053517632465, 'fraction_numerical': 0.012759170653907496, 'mean_word_length': 5.377401129943503, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '5733', 'license': 'Apache-2.0', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1701, 'n_words': 636, 'path': 'notebooks/03_aoe2_civgen.ipynb', 'repo_name': 'lukexyz/insultswordfight', 'size': '5643'}