以下は、評価論文で述べられている3層階層を実装したサンプルコードである：

```
import transformers
import torch

class ScriptGenerator:
    def __init__(self)：
        self.model = transformers.pipeline("text-generation", model="xlm-roberta-base")

    def generate_script(self, central_conflict)：
        # 最上位レイヤ：ユーザー入力
        文字, plot_outline, location = self.middle_layer(central_conflict)
        script_text = self.bottom_layer(characters, plot_outline, locations)
        return script_text

    def middle_layer(self, central_conflict)：
        # キャラクターの説明を生成する
        characters = self.generate_characters()
        # プロットのアウトラインと場所を生成する
        plot_outline, locations = self.generate_plot_outline(central_conflict)
        return characters, plot_outline, locations

    def bottom_layer(self, characters, plot_outline, locations)：
        # キャラクターの台詞を生成する
        script_text = self.generate_dialogue(characters, plot_outline, locations)
        return script_text

    def generate_characters(self)：
        prompt = "演劇や映画のキャラクターの説明を生成する"
        character_description = self.model(prompt, max_length=1024, num_return_sequences=1)[0].generated_text
        return character_description

    def generate_plot_outline(self, central_conflict)：
        prompt = f"{central_conflict}という中心的な対立を持つ演劇または映画のプロットアウトラインを生成する"
        plot_outline = self.model(prompt, max_length=1024, num_return_sequences=1)[0].generated_text
        # プロットアウトラインから位置を抽出
        location = self.extract_locations(plot_outline)
        return plot_outline, locations

    def extract_locations(self, plot_outline)：
        # プロットアウトラインから位置を抽出するコード
        location = [] # ダミーコード。
        # 実際の実装に置き換える
        location.append("A quiet coffee shop")
        locations.append("A busy city street")
        return locations

    def generate_dialogue(self, characters, plot_outline, locations)：
        prompt = f "次の登場人物で、演劇か映画の台詞を生成してください：{characters}とプロットのアウトライン：{plot_outline}と location：{場所}"
        dialogue = self.model(prompt, max_length=1024, num_return_sequences=1)[0].generated_text
        return dialogue

if __name__ == "__main__"：
    generator = ScriptGenerator()
    central_conflict = "離ればなれになった2人の兄弟は、家業を財政破綻から救うために再会しなければならない。"
    script_text = generator.generate_script(central_conflict)
    print(script_text)
```

このコードでは、Hugging Face Transformersライブラリと、事前に訓練された言語モデルのチェックポイントを使用して、スクリプト・テキストを生成しています。関数は3つの階層に編成されており、最上位層はドラマの中心となる葛藤を説明する1文を受け入れ、中間層はキャラクターの説明、プロットの概要、場所の説明を生成し、最下層はスクリプトのキャラクターのセリフを生成します。
Here is a sample code that implements the three-layer hierarchy described in the evaluation paper:


import transformers
import torch

class ScriptGenerator:
    def __init__(self):
        self.model = transformers.pipeline("text-generation", model="xlm-roberta-base")

    def generate_script(self, central_conflict):
        # highest layer: user input
        characters, plot_outline, locations = self.middle_layer(central_conflict)
        script_text = self.bottom_layer(characters, plot_outline, locations)
        return script_text

    def middle_layer(self, central_conflict):
        # generate character descriptions
        characters = self.generate_characters()
        # generate plot outline and locations
        plot_outline, locations = self.generate_plot_outline(central_conflict)
        return characters, plot_outline, locations

    def bottom_layer(self, characters, plot_outline, locations):
        # generate character dialogue
        script_text = self.generate_dialogue(characters, plot_outline, locations)
        return script_text

    def generate_characters(self):
        prompt = "Generate a description of a character for a play or movie."
        character_description = self.model(prompt, max_length=1024, num_return_sequences=1)[0].generated_text
        return character_description

    def generate_plot_outline(self, central_conflict):
        prompt = f"Generate a plot outline for a play or movie with the central conflict: {central_conflict}"
        plot_outline = self.model(prompt, max_length=1024, num_return_sequences=1)[0].generated_text
        # extract locations from plot outline
        locations = self.extract_locations(plot_outline)
        return plot_outline, locations

    def extract_locations(self, plot_outline):
        # code to extract locations from plot outline
        locations = []
        # dummy code, replace with actual implementation
        locations.append("A quiet coffee shop")
        locations.append("A busy city street")
        return locations

    def generate_dialogue(self, characters, plot_outline, locations):
        prompt = f"Generate dialogue for a play or movie with the following characters: {characters} and plot outline: {plot_outline} and locations: {locations}"
        dialogue = self.model(prompt, max_length=1024, num_return_sequences=1)[0].generated_text
        return dialogue

if __name__ == "__main__":
    generator = ScriptGenerator()
    central_conflict = "Two estranged brothers must reunite to save their family business from financial ruin."
    script_text = generator.generate_script(central_conflict)
    print(script_text)


This code uses the Hugging Face Transformers library and a pre-trained language model checkpoint to generate script text. The functions are organized into three hierarchical layers, with the highest layer accepting a single sentence describing the central dramatic conflict, the middle layer generating character descriptions, a plot outline, and location descriptions, and the bottom layer generating character dialogue for the script.