Beispiel #1
0
    def __get_word2vec_saved_model(self):
        model = None
        path = get_complet_path('keras_models') + "/word2vec.model"
        if (Path(path).is_file()):
            model = Word2Vec.load(path)

        return model, path
Beispiel #2
0
def get_saved_model(name):
    model = None
    path = get_complet_path('keras_models') + "/" + name + ".h5"

    # We save/load model to improve performance
    if (Path(path).is_file()):
        model = load_model(path)

    return model, path
Beispiel #3
0
def main():
    corpus = get_file_content_with_br(get_complet_path("proverbes.txt"))
    tests = json.loads(get_file_content(get_complet_path("test1.txt")))

    tokens = tokenize_text(corpus)
    tokens.append("UNK")

    complet_proverbe_with_trigram(tokens, tests)

    # First solution
    complet_proverbe_with_unigram(tokens, tests)
    complet_proverbe_with_bigram(tokens, tests)
    complet_proverbe_with_trigram(tokens, tests)

    # Second solution with laplace
    complet_with_ngram(tokens, tests, ngram_number=1, laplace=1)
    complet_with_ngram(tokens, tests, ngram_number=2, laplace=0)

    complet_with_ngram(tokens, tests, ngram_number=3, laplace=0)
    complet_with_ngram(tokens, tests, ngram_number=3, laplace=10)

    # Perplexity
    perplexity_of_sentence("a beau mentir qui vient de loin", tokens, 0)
    perplexity_of_sentence("something not trained in our model", tokens, 0)
Beispiel #4
0
def main():
    ingredients_text = get_file_content(get_complet_path("ingredients.txt"))
    solutions_text = get_file_content(get_complet_path("ingredients_solutions.txt"))

    quantity_correct = 0
    quantity_wrong = 0

    print("###################### SOLUTION")

    for count,ingredient_text in ingredients_text.items():
        ingredient = get_ingredient(ingredient_text)
        ingredient_solution = solutions_text[count].split("   ")
        solution_quantity = ingredient_solution[1].replace("QUANTITE:","")
        solution_item = ingredient_solution[2].replace("INGREDIENT:","")

        if (solution_quantity == ingredient.quantity and solution_item == ingredient.item):
            quantity_correct +=1
        else:
            quantity_wrong +=1
            print("NOT MATCH:\n {!r} \n Solution  (item='{}', quantity='{}')\n".format(ingredient, solution_item,solution_quantity))

    succes_rate = quantity_correct * 100 / len(ingredients_text)
    print("\nResult: CORRECT({}) x WRONG({}) - {:.2f}%".format(quantity_correct, quantity_wrong, succes_rate))
    print()
Beispiel #5
0
def remove_saved_keras_models(remove_models):
    if (remove_models):
        files = glob.glob(get_complet_path("keras_models") + '/*')
        for f in files:
            os.remove(f)