Instructions to use OneclickAI/LSTM_GUE_test_Model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use OneclickAI/LSTM_GUE_test_Model with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://OneclickAI/LSTM_GUE_test_Model") - Notebooks
- Google Colab
- Kaggle
Download train.py from OneclickAI/LSTM_GUE_test_Model: direct link, hf CLI and curl.
- Browser
- Download file 2.87 kB
-
https://huggingface.co/OneclickAI/LSTM_GUE_test_Model/resolve/main/train.py
- Command line
-
hf download hf://OneclickAI/LSTM_GUE_test_Model/train.py
-
curl -L -o train.py https://huggingface.co/OneclickAI/LSTM_GUE_test_Model/resolve/main/train.py
2.87 kB
| import numpy as np | |
| import tensorflow as tf | |
| from tensorflow import keras | |
| from keras import layers | |
| print("TensorFlow ๋ฒ์ :", tf.__version__) | |
| # 1. ๋ฐ์ดํฐ ๋ก๋ ๋ฐ ์ ์ฒ๋ฆฌ | |
| print("\n1. ๋ฐ์ดํฐ ๋ก๋ ๋ฐ ์ ์ฒ๋ฆฌ๋ฅผ ์์ํฉ๋๋ค...") | |
| # num_words=10000: ๊ฐ์ฅ ๋น๋๊ฐ ๋์ 1๋ง ๊ฐ์ ๋จ์ด๋ง ์ฌ์ฉ | |
| (x_train, y_train), (x_test, y_test) = keras.datasets.imdb.load_data(num_words=10000) | |
| print(f"ํ์ต ๋ฐ์ดํฐ ๊ฐ์: {len(x_train)}") | |
| print(f"ํ ์คํธ ๋ฐ์ดํฐ ๊ฐ์: {len(x_test)}") | |
| # ๋ฌธ์ฅ์ ๊ธธ์ด๋ฅผ ๋์ผํ๊ฒ ๋ง์ถ๊ธฐ ์ํด ํจ๋ฉ(padding) ์ฒ๋ฆฌ (maxlen=256) | |
| x_train = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=256) | |
| x_test = keras.preprocessing.sequence.pad_sequences(x_test, maxlen=256) | |
| print("๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ๊ฐ ์๋ฃ๋์์ต๋๋ค.") | |
| # 2. LSTM ๋ชจ๋ธ ์์ฑ, ํ์ต ๋ฐ ์ ์ฅ | |
| print("\n2. LSTM ๋ชจ๋ธ ํ์ต์ ์์ํฉ๋๋ค...") | |
| # LSTM ๋ชจ๋ธ ์ํคํ ์ฒ ์ ์ | |
| lstm_model = keras.Sequential([ | |
| layers.Embedding(input_dim=10000, output_dim=128), | |
| layers.LSTM(64), | |
| layers.Dense(1, activation="sigmoid") | |
| ]) | |
| # ๋ชจ๋ธ ์ปดํ์ผ | |
| lstm_model.compile( | |
| loss="binary_crossentropy", | |
| optimizer="adam", | |
| metrics=["accuracy"] | |
| ) | |
| print("\n--- LSTM ๋ชจ๋ธ ๊ตฌ์กฐ ---") | |
| lstm_model.summary() | |
| # ๋ชจ๋ธ ํ์ต | |
| batch_size = 128 | |
| epochs = 1 # ์์ ์ด๋ฏ๋ก epoch๋ฅผ ์ค์ฌ์ ์คํ ์๊ฐ์ ๋จ์ถํฉ๋๋ค. | |
| history_lstm = lstm_model.fit( | |
| x_train, y_train, | |
| batch_size=batch_size, | |
| epochs=epochs, | |
| validation_data=(x_test, y_test) | |
| ) | |
| # ๋ชจ๋ธ ํ๊ฐ | |
| score_lstm = lstm_model.evaluate(x_test, y_test, verbose=0) | |
| print(f"\nLSTM ๋ชจ๋ธ ํ ์คํธ ๊ฒฐ๊ณผ -> Loss: {score_lstm[0]:.4f}, Accuracy: {score_lstm[1]:.4f}\n") | |
| # ํ์ต๋ LSTM ๋ชจ๋ธ ์ ์ฅ | |
| lstm_model.save("lstm_model.keras") | |
| print("LSTM ๋ชจ๋ธ์ด 'lstm_model.keras' ํ์ผ๋ก ์ ์ฅ๋์์ต๋๋ค.") | |
| # 3. GRU ๋ชจ๋ธ ์์ฑ, ํ์ต ๋ฐ ์ ์ฅ | |
| print("\n3. GRU ๋ชจ๋ธ ํ์ต์ ์์ํฉ๋๋ค...") | |
| # GRU ๋ชจ๋ธ ์ํคํ ์ฒ ์ ์ | |
| gru_model = keras.Sequential([ | |
| layers.Embedding(input_dim=10000, output_dim=128), | |
| layers.GRU(64), | |
| layers.Dense(1, activation="sigmoid") | |
| ]) | |
| # ๋ชจ๋ธ ์ปดํ์ผ | |
| gru_model.compile( | |
| loss="binary_crossentropy", | |
| optimizer="adam", | |
| metrics=["accuracy"] | |
| ) | |
| print("\n--- GRU ๋ชจ๋ธ ๊ตฌ์กฐ ---") | |
| gru_model.summary() | |
| # ๋ชจ๋ธ ํ์ต | |
| history_gru = gru_model.fit( | |
| x_train, y_train, | |
| batch_size=batch_size, | |
| epochs=epochs, | |
| validation_data=(x_test, y_test) | |
| ) | |
| # ๋ชจ๋ธ ํ๊ฐ | |
| score_gru = gru_model.evaluate(x_test, y_test, verbose=0) | |
| print(f"\nGRU ๋ชจ๋ธ ํ ์คํธ ๊ฒฐ๊ณผ -> Loss: {score_gru[0]:.4f}, Accuracy: {score_gru[1]:.4f}") | |
| # ํ์ต๋ GRU ๋ชจ๋ธ ์ ์ฅ | |
| gru_model.save("gru_model.keras") | |
| print("GRU ๋ชจ๋ธ์ด 'gru_model.keras' ํ์ผ๋ก ์ ์ฅ๋์์ต๋๋ค.") |