Skip to content

Commit 39e3710

Browse files
Merge pull request #150 from david-thrower/148-tensorflow-upgrades
2 parents 7530497 + 1463026 commit 39e3710

File tree

8 files changed

+72
-30
lines changed

8 files changed

+72
-30
lines changed

.github/workflows/automerge.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ name: Python application
55

66
on:
77
push:
8-
branches: [ "main", "125-add-use-cases-gpt2-encoder-for-phishing-email-detection" ]
8+
branches: [ "main", "148-tensorflow-upgrades" ]
99

1010
permissions:
1111
contents: read
1212

1313
jobs:
1414
build:
1515
runs-on: ubuntu-latest
16+
# container:
17+
# image: python:33.11.9
1618
steps:
1719
- uses: actions/checkout@v3
1820
- name: Test Cerebros
1921
uses: actions/setup-python@v3
2022
with:
21-
python-version: "3.10.4"
23+
python-version: "3.11"
2224
- name: Install dependencies
2325
run: |
2426
python -m pip install --upgrade pip

cerebros/simplecerebrosrandomsearch/simple_cerebros_random_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def run_moity_permutations(self, spec, subtrial_number, lock):
502502
with open(neural_network_spec_file, 'w') as f:
503503
f.write(str(spec))
504504
next_model_name =\
505-
f"{self.project_name}/models/tr_{str(self.trial_number).zfill(16)}_subtrial_{str(subtrial_number).zfill(16)}"\
505+
f"{self.project_name}/models/tr_{str(self.trial_number).zfill(16)}_subtrial_{str(subtrial_number).zfill(16)}.keras"\
506506
.lower()
507507
neural_network.save(next_model_name)
508508
oracle_0['trial_number'] = self.trial_number

cerebros/units/units.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ def __init__(self,
8383
train_data_dtype=tf.float32,
8484
*args,
8585
**kwargs):
86-
87-
self.input_shape = input_shape
86+
if isinstance(input_shape, int):
87+
self.input_shape = (input_shape,)
88+
elif isinstance(input_shape, str):
89+
self.input_shape = (int(input_shape),)
90+
else:
91+
_input_shape = [int(ax) for ax in input_shape]
92+
self.input_shape = tuple(_input_shape)
8893
self.neural_network_layer = []
8994
self.base_models = base_models
9095
self.train_data_dtype = train_data_dtype

cicd-requirements.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
matplotlib==3.6.2
2-
tensorflow-text==2.12.0
3-
keras-nlp==0.6.2
4-
scikit-learn==1.3.2
1+
matplotlib==3.8.4
2+
tensorflow-text==2.15.0
3+
keras-nlp==0.9.1
4+
scikit-learn==1.4.1.post1
5+
tensorflow-hub==0.16.1

regression-example-ames-no-preproc-val-set.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,26 @@ def hash_based_split(df, # Pandas dataframe
122122
print(f"Shape of train data: {train_data_np.shape}")
123123

124124
tensor_x =\
125-
tf.constant(train_df.values)
125+
tf.constant(train_df.values, dtype=tf.float32)
126126

127127

128128
training_x = [tensor_x]
129129

130130
INPUT_SHAPES = [training_x[i].shape[1] for i in np.arange(len(training_x))]
131131

132-
train_labels = [train_labels_pd.values]
132+
train_labels = [tf.constant(train_labels_pd.values.astype(float), dtype=tf.float32)]
133133
print(f"Shape of train labels: {train_labels_pd.shape}")
134134

135135
OUTPUT_SHAPES = [1] # [train_labels[i].shape[1]
136136

137137
## Val set:
138138

139139
print(f"Shape of val data: {val_df.shape}")
140-
val_tensor_x = tf.constant(val_df.values)
140+
val_tensor_x = tf.constant(val_df.values, dtype=tf.float32)
141141
val_x = [val_tensor_x]
142142

143143

144-
val_labels = [val_labels_pd.values]
144+
val_labels = [tf.constant(val_labels_pd.values.astype(float), dtype=tf.float32)]
145145
print(f"Shape of val labels: {val_labels_pd.shape}")
146146

147147
# Params for a training function (Approximately the oprma

regression-example-ames-no-preproc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
INPUT_SHAPES = [training_x[i].shape[1] for i in np.arange(len(training_x))]
4545

46-
train_labels = [label.values]
46+
train_labels = [tf.constant(label.values.astype(float))]
4747

4848
OUTPUT_SHAPES = [1] # [train_labels[i].shape[1]
4949

requirements.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
jax==0.4.1
2-
jaxlib==0.4.1
3-
pendulum==2.1.2
4-
tensorflow==2.12.0
5-
numpy==1.23.5
6-
pandas==2.0.3
7-
pyvis==0.3.1
8-
plotly==5.11.0
9-
matplotlib==3.6.2
10-
tensorflow-text==2.12.0
11-
imageio==2.25.0
1+
jax==0.4.26
2+
jaxlib==0.4.26
3+
pendulum==3.0.0
4+
tensorflow==2.15.0
5+
numpy==1.26.4
6+
pandas==2.2.1
7+
pyvis==0.3.2
8+
plotly==5.20.0
9+
matplotlib==3.8.4
10+
imageio==2.34.0

text-class-ham-or-spam.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,52 @@
4545

4646

4747
# Build BERT base model
48+
# text_input = tf.keras.layers.Input(shape=(), dtype=tf.string)
49+
# preprocessor = hub.KerasLayer(
50+
# "https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3")
51+
# encoder_inputs = preprocessor(text_input)
52+
53+
###
54+
# preprocessor = hub.load(
55+
# "https://www.kaggle.com/models/tensorflow/bert/TensorFlow2/en-uncased-preprocess/3")
56+
# inp = tf.keras.layers.Input(shape=(), dtype=tf.string)
57+
# text_inputs = [inp]
58+
# tokenize = hub.KerasLayer(preprocessor.tokenize)
59+
# tokenized_inputs = [tokenize(segment) for segment in text_inputs]
60+
61+
# seq_length = 128 # Your choice here.
62+
# bert_pack_inputs = hub.KerasLayer(
63+
# preprocessor.bert_pack_inputs,
64+
# arguments=dict(seq_length=seq_length)) # Optional argument.
65+
# encoder_inputs = bert_pack_inputs(tokenized_inputs)
66+
# ###
67+
68+
69+
70+
# encoder = hub.KerasLayer(
71+
# "https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/4",
72+
# trainable=True)
73+
# outputs = encoder(encoder_inputs)
74+
# pooled_output = outputs["pooled_output"] # [batch_size, 768].
75+
# sequence_output = outputs["sequence_output"] # [batch_size, seq_length, 768].
76+
# embedding_model = tf.keras.Model(inp, pooled_output)
77+
78+
79+
###
4880
text_input = tf.keras.layers.Input(shape=(), dtype=tf.string)
4981
preprocessor = hub.KerasLayer(
50-
"https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3")
82+
"https://kaggle.com/models/tensorflow/bert/TensorFlow2/en-uncased-preprocess/3")
5183
encoder_inputs = preprocessor(text_input)
5284
encoder = hub.KerasLayer(
53-
"https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/4",
85+
"https://www.kaggle.com/models/tensorflow/bert/TensorFlow2/bert-en-uncased-l-10-h-128-a-2/2",
5486
trainable=True)
5587
outputs = encoder(encoder_inputs)
56-
pooled_output = outputs["pooled_output"] # [batch_size, 768].
57-
sequence_output = outputs["sequence_output"] # [batch_size, seq_length, 768].
88+
pooled_output = outputs["pooled_output"] # [batch_size, 128].
89+
sequence_output = outputs["sequence_output"] # [batch_size, seq_length, 128].
90+
5891
embedding_model = tf.keras.Model(text_input, pooled_output)
92+
###
93+
5994

6095
## Load the Data set
6196
raw_text = pd.read_csv(data_file, dtype='object')
@@ -68,7 +103,7 @@
68103
labels = labels.values
69104
data = raw_text.values
70105

71-
labels_tensor = tf.constant(labels, dtype=tf.int8)
106+
labels_tensor = tf.constant(labels, dtype=tf.float32)
72107
data_tensor = tf.constant(data, dtype=tf.string)
73108

74109
TIME = pendulum.now(tz='America/New_York').__str__()[:16]\

0 commit comments

Comments
 (0)