Пример #1
0
    def create_navigation(self, navigation_html, experiment_folder,
                          experiment_path, data):
        if experiment_folder != "":
            if os.path.exists(experiment_path + "/custom_flexp_chain.py"):
                try:
                    custom_flexp_chain = import_by_filename(
                        'custom_flexp_chain',
                        experiment_path + "/custom_flexp_chain.py")
                    html_chain = custom_flexp_chain.get_chain()
                    html_chain = Chain(html_chain)
                except:
                    html_chain = Chain([
                        StringToHtml(
                            "<h2>Error processing custom chain. {}</h2>".
                            format(traceback.format_exc().replace(
                                "\n", "</br>")),
                            title="Error in custom chain")
                    ] + self.html_chain.modules)
                finally:
                    if "custom_flexp_chain" in sys.modules:
                        del sys.modules["custom_flexp_chain"]

            else:
                html_chain = self.html_chain
            html_chain.process(data)
            html_chain.close()

            navigation_html = html_anchor_navigation(
                experiment_path, experiment_folder,
                html_chain) + navigation_html
        return navigation_html
Пример #2
0
 def test_with(self):
     c = Chain([
         Add(13),
     ])
     data = {"input": 10}
     with c:
         c.process(data)
     assert data == {"input": 10, "output": 23}
Пример #3
0
    def test_chain_from_fuction(self):
        data = {"input": 10}

        def add(x):
            x["output"] = x["input"] + 13

        c = Chain(add)
        c.process(data)
        self.assertEqual(data, {"input": 10, "output": 23})
        assert str(c) == "Chain[add]"
Пример #4
0
 def test_time(self):
     data = {"input": 10}
     c = Chain([
         Add(13),
     ])
     c.process(data)
     c.close()
     assert len(c.times) == 1
     assert c.iterations == 1
     c.process(data)
     assert c.iterations == 2
Пример #5
0
 def test_chain_inspect_deep(self):
     data = {"input": {i: i for i in range(11)}}
     with LogCapture() as l:
         c = Chain([
             inspector.inspect(DummyModule(), stream=True)])
         c.process(data)
         c.close()
         l.check(
             ('flexp.flow.flow', 'DEBUG', 'DummyModule.process()'),
             ('flexp.flow.inspector', 'INFO', 'Data flow structure'),
             ('flexp.flow.inspector', 'INFO', "{\'input\': {\"<class \'int\'>#11 times (0)\": 0}}"),
             ('flexp.flow.inspector', 'INFO', 'End of data flow structure'),
             ('flexp.flow.flow', 'INFO', 'DummyModule average execution time 0.00 sec')
         )
Пример #6
0
 def test_chain_inspect(self):
     data = {"input": 20}
     with LogCapture() as l:
         c = Chain([
             inspector.inspect(Add(10), stream=True)])
         c.process(data)
         c.close()
         l.check(
             ('flexp.flow.flow', 'DEBUG', 'Add.process()'),
             ('flexp.flow.inspector', 'INFO', 'Data flow structure'),
             ('flexp.flow.inspector', 'INFO', "{'input': 20, 'output': 30}"),
             ('flexp.flow.inspector', 'INFO', 'End of data flow structure'),
             ('flexp.flow.flow', 'INFO', 'Add average execution time 0.00 sec')
         )
Пример #7
0
    def test_chain(self):
        data = {"input": 10}
        c = Chain([
            Add(13),
        ])
        c.process(data)
        c.close()

        self.assertEqual(data, {"input": 10, "output": 23})
        assert str(c) == "Chain[Add]"
        c.add(Mult(2))
        assert str(c) == "Chain[Add-Mult]"
        c.process(data)
        self.assertEqual(data, {"input": 10, "output": 20})
Пример #8
0
 def test_chain_from_object(self):
     data = {"input": 10}
     c = Chain(Add(13))
     c.process(data)
     self.assertEqual(data, {"input": 10, "output": 23})
     assert str(c) == "Chain[Add]"
Пример #9
0
flexp.describe("Query parameter prediction with TF-IDF and linear regression")

# Setup logging
log.debug("flow setup complete.")

# Create the chain to load the data, lowercase and tokenize it.
file_name = "example_queries.tsv"
data_chain = Chain([
    LoadData(file_name),
    Lowercase(),
    TfIdf(),
])

# data["id"] should contain all info required to replicate the experiment.
data = {"id": file_name}
data_chain.process(data)
data_chain.close()
log.debug("Data chain complete.")

# Train and evaluate a classifier
train_chain = Chain([
    # Create data["train"] and data["dev"]
    TrainTestSplit(),
    # Train our classifier on data["train"]
    Train(),
    # Evaluate the classifier and store the results in the experiment folder
    # using flexp.get_file_path("results.csv")
    Eval(),
])
train_chain.process(data)
train_chain.close()
Пример #10
0
    def get(self):
        experiment_folder = self.get_argument("experiment", default="")
        experiment_path = path.join(self.experiments_folder, experiment_folder)

        if not path.isdir(experiment_path):
            experiment_folder = ""

        navigation_html = html_navigation(self.experiments_folder, experiment_folder)
        header_html = ""
        scripts_html = ""

        if experiment_folder != "":
            data = {"experiment_path": experiment_path,
                    "experiment_folder": experiment_folder,
                    "html": [],
                    "header": dict(),
                    "scripts": dict()
                    }
            # Use custom chain, if present
            if os.path.exists(experiment_path + "/custom_flexp_chain.py"):
                try:
                    custom_flexp_chain = import_by_filename('custom_flexp_chain',
                                                            experiment_path + "/custom_flexp_chain.py")
                    html_chain = custom_flexp_chain.get_chain()
                    html_chain = Chain(html_chain)
                except:
                    html_chain = Chain([StringToHtml("<h2>Error processing custom chain. {}</h2>"
                                                     .format(traceback.format_exc().replace("\n", "</br>")),
                                                     title="Error in custom chain")] + self.html_chain.modules)
                finally:
                    if "custom_flexp_chain" in sys.modules:
                        del sys.modules["custom_flexp_chain"]

            else:
                html_chain = self.html_chain
            html_chain.process(data)
            html_chain.close()

            title_html = "<h1>{}</h1>".format(experiment_folder)
            content_html = u"\n".join(data['html'])
            navigation_html = html_anchor_navigation(
                experiment_path, experiment_folder, html_chain) + navigation_html

            header_html = u"\n".join(u"\n".join(html_lines)
                                     for head_section, html_lines
                                     in data["header"].items())

            scripts_html = u"\n".join(u"\n".join(script_lines)
                                      for script_section, script_lines
                                      in data["scripts"].items())

        else:
            title_html = "<h1>Experiments</h1>"
            content_html = html_table(self.experiments_folder, self.get_metrics_fcn, self.metrics_file)

        html = self._template.format(
            title=title_html,
            navigation=navigation_html,
            content=content_html,
            header=header_html,
            scripts=scripts_html)
        self.write(html)