Skip to content

Commit

Permalink
load bert model from keras_nlp:
Browse files Browse the repository at this point in the history
- problems with hub keras layers google-research/bert#1401
  • Loading branch information
mojc committed Sep 12, 2024
1 parent b022249 commit bdff649
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bert_scoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pandas as pd
import numpy as np

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
import keras_nlp

import tensorflow_text as text
import tensorflow_hub as hub

from sklearn.model_selection import train_test_split

data = pd.read_csv("learning-agency-lab-automated-essay-scoring-2/train.csv")

X_train, X_val, y_train, y_val = train_test_split(data['full_text'], data['score'], test_size=0.2, random_state=42)
print(X_train.shape, X_val.shape, y_train.shape, y_val.shape )

text_input = tf.keras.layers.Input(shape=(), dtype=tf.string)
preprocessor = keras_nlp.models.BertPreprocessor.from_preset("bert_base_en_uncased",trainable=True)

encoder_inputs = preprocessor(text_input)

0 comments on commit bdff649

Please sign in to comment.