Skip to content

Commit

Permalink
Jm/py 3.6 (#19)
Browse files Browse the repository at this point in the history
* Modify TYPE_CHECKING annotations for py3.6 support

* Install dataclasses for CI/CD for py3.6 usage

* README update

* Add dataclasses to setup as an extra for 3.6 support

Co-authored-by: John Myers <john@gretel.ai>
  • Loading branch information
johntmyers and John Myers committed May 22, 2020
1 parent e164132 commit d64a9c3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.6
- name: Install
run: |
pip install dataclasses==0.7
pip install -e .
pip install -r test-requirements.txt
- name: Lint
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Documentation Status](https://readthedocs.org/projects/gretel-synthetics/badge/?version=stable)](https://gretel-synthetics.readthedocs.io/en/stable/?badge=stable)


This code has been developed and tested on Python 3.7. Python 3.8 is currently unsupported.
This code has been developed and tested on Python 3.7. Python 3.8 is currently unsupported. While not developed on Python 3.6, this code will run in Google Colab, which currently uses 3.6. If you wish to use Python 3.6, out side of Google Colab, you may install with the `3.6` extras: `pip install gretel-synthetics[tf,3.6]`, for example.

This package allows developers to quickly get immersed with synthetic data generation through the use of neural networks. The more complex pieces of working with libraries like Tensorflow and differential privacy are bundled into friendly Python classes and functions.

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'numpy==1.18.3'
],
extras_require={
'tf': ['tensorflow==2.1.0']
'tf': ['tensorflow==2.1.0'],
'3.6': ['dataclasses==0.7']
}
)
11 changes: 5 additions & 6 deletions src/gretel_synthetics/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
- Created a config
- Trained a model
"""
from __future__ import annotations
import logging
import sentencepiece as spm
import tensorflow as tf
Expand Down Expand Up @@ -69,14 +68,14 @@ def values_as_list(self) -> List[str]:
)


def _load_tokenizer(store: _BaseConfig) -> spm.SentencePieceProcessor:
def _load_tokenizer(store: "_BaseConfig") -> spm.SentencePieceProcessor:
logging.info("Loading SentencePiece tokenizer")
sp = spm.SentencePieceProcessor()
sp.Load(store.tokenizer_model)
return sp


def _prepare_model(sp: spm, batch_size: int, store: _BaseConfig) -> tf.keras.Sequential:
def _prepare_model(sp: spm, batch_size: int, store: "_BaseConfig") -> tf.keras.Sequential:
model = _build_sequential_model(
vocab_size=len(sp), batch_size=batch_size, store=store
)
Expand All @@ -91,14 +90,14 @@ def _prepare_model(sp: spm, batch_size: int, store: _BaseConfig) -> tf.keras.Seq
return model


def _load_model(store: _BaseConfig) -> Tuple[spm.SentencePieceProcessor, tf.keras.Sequential]:
def _load_model(store: "_BaseConfig") -> Tuple[spm.SentencePieceProcessor, tf.keras.Sequential]:
sp = _load_tokenizer(store)
model = _prepare_model(sp, 1, store)
return sp, model


def generate_text(
store: _BaseConfig, start_string: str = "<n>", line_validator: callable = None
store: "_BaseConfig", start_string: str = "<n>", line_validator: callable = None
):
"""A generator that will load a model and start creating records.
Expand Down Expand Up @@ -169,7 +168,7 @@ def _predict_chars(
model: tf.keras.Sequential,
sp: spm.SentencePieceProcessor,
start_string: str,
store: _BaseConfig,
store: "_BaseConfig",
) -> str:
"""
Evaluation step (generating text using the learned model).
Expand Down

0 comments on commit d64a9c3

Please sign in to comment.