<jupyter_start><jupyter_text>TODO- Test the ``chess`` library    - Convert to numpy array    - Gif - Use pre-existing GameAI- Create GameAI with minimax techniques- Evaluation function for each move- Move recommendation "à la" AlphaGo, MCTS ?- Notebook interface to play- Adaptive GameAI  Test of the ``chess`` libraryhttps://python-chess.readthedocs.io/en/latest/  Playground<jupyter_code>import sys
sys.path.append("../")

from beth.game import Game
from beth.players.random_player import RandomPlayer
from beth.players.human_player import HumanPlayer
from beth.players.sequence import SequenceGame,SequencePlayer
black = RandomPlayer()
white = RandomPlayer()

# white = HumanPlayer()
# black = HumanPlayer()

game = Game(white,black)
game.reset_game()
game.run()
game.board.is_seventyfive_moves()<jupyter_output><empty_output><jupyter_text>Game exploration<jupyter_code>games = pd.read_csv("../data/raw/kaggle/games.csv")
games.shape
"start " + games["moves"].head()
game = games.iloc[2]

seq_str = game["moves"]
winner = game["winner"]
victory_status = game["victory_status"]
seq = SequenceGame(seq_str,0.1,victory_status,winner)
game = Game(seq.white,seq.black)
seq_str
seq.victory_status
game.run()<jupyter_output><empty_output><jupyter_text>https://pytorch.org/tutorials/beginner/transformer_tutorial.html  Experiment 1 using LSTMshttps://www.kdnuggets.com/2020/07/pytorch-lstm-text-generation-tutorial.html<jupyter_code>from beth.models.dataset import Dataset
from beth.utils import make_experiment
from beth.models.lstm import LSTMModel
from beth.players.ai_player import AIPlayer<jupyter_output><empty_output><jupyter_text>Init classes<jupyter_code>games = pd.read_csv("../data/raw/kaggle/games.csv")
moves = "start " + games["moves"]
moves.head()
moves[0]
dataset = Dataset(moves)
len(dataset.uniq_words)<jupyter_output><empty_output><jupyter_text>Train loop<jupyter_code>experiment = make_experiment("../.env","Simple LSTM",["NLP","LSTM"])
params = {
    "sequence_length":10,
    "batch_size":32,
    "max_epochs":1,
    "lr":0.01,
    "lstm_size":128,
    "embedding_dim":128,
    "num_layers":3,
}
model = LSTMModel(dataset,**params)
experiment.log_parameters(params)
model.fit(**params)
# experiment.end()
model.save_weights("lstm_20122020.pth")
experiment.log_text("Learning rate does not seem to accelerate anything here, let's stick to around 0.001")
experiment.end()
p = model.predict("start",1,as_proba = True)
p
p[0].sort_values(ascending = False).head(10)<jupyter_output><empty_output><jupyter_text>Test in games<jupyter_code>model = LSTMModel(dataset)
model.load_weights("lstm_20122020.pth")
# black = RandomPlayer()
# white = RandomPlayer()

white = AIPlayer(brain=model,wait = 1)
black = AIPlayer(brain=model,wait = 1)

# white = HumanPlayer()
# black = HumanPlayer()

game = Game(white,black)
game.run()
p = model.predict_next(game)[0]
p.loc[game.get_legal_moves_san()].sort_values(ascending = False)
stack[0]
x = stack[0]
game.board.san(stack[1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14047936085219706, 'fraction_numerical': 0.018641810918774968, 'mean_word_length': 6.626903553299492, 'pattern_counts': {'":': 7, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '573468', 'license': 'MIT', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1084, 'n_words': 188, 'path': 'notebooks/20200512 - LSTM Model.ipynb', 'repo_name': 'TheoLvs/beth', 'size': '3004'}