Instructions to use pemix09/paperstack_document_data_retrieval with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use pemix09/paperstack_document_data_retrieval with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0. # See https://github.com/keras-team/tf-keras for more details. # !pip install "huggingface_hub<1.0" tf_keras from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("pemix09/paperstack_document_data_retrieval") - Notebooks
- Google Colab
- Kaggle
Download summarizer/convert_to_tflite.py from pemix09/paperstack_document_data_retrieval: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/pemix09/paperstack_document_data_retrieval/resolve/main/summarizer/convert_to_tflite.py
- Command line
-
hf download hf://pemix09/paperstack_document_data_retrieval/summarizer/convert_to_tflite.py
-
curl -L -o convert_to_tflite.py https://huggingface.co/pemix09/paperstack_document_data_retrieval/resolve/main/summarizer/convert_to_tflite.py
1.97 kB
| import os | |
| import tensorflow as tf | |
| from transformers import TFT5ForConditionalGeneration, AutoTokenizer | |
| from pathlib import Path | |
| BASE_DIR = Path(__file__).resolve().parent.parent | |
| MODEL_INPUT_DIR = BASE_DIR / "summarizer" / "models" / "flan_t5_custom" | |
| TFLITE_OUTPUT_FILE = BASE_DIR / "summarizer" / "models" / "summarizer.tflite" | |
| # USTAWAMY IDENTYCZNE WARTOŚCI - to rozwiązuje błąd "not broadcastable" | |
| MAX_LEN = 256 | |
| def convert(): | |
| print(f"🚀 Konwersja z wyrównaniem kształtów do {MAX_LEN}...") | |
| model = TFT5ForConditionalGeneration.from_pretrained(MODEL_INPUT_DIR, from_pt=True) | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_INPUT_DIR) | |
| class T5MergedModel(tf.Module): | |
| def __init__(self, model): | |
| super(T5MergedModel, self).__init__() | |
| self.model = model | |
| def __call__(self, input_ids, decoder_input_ids): | |
| # training=False jest kluczowe dla usunięcia węzłów treningowych | |
| output = self.model(input_ids=input_ids, decoder_input_ids=decoder_input_ids, training=False) | |
| return output.logits | |
| t5_module = T5MergedModel(model) | |
| converter = tf.lite.TFLiteConverter.from_concrete_functions( | |
| [t5_module.__call__.get_concrete_function()], t5_module | |
| ) | |
| converter.target_spec.supported_ops = [ | |
| tf.lite.OpsSet.TFLITE_BUILTINS, | |
| tf.lite.OpsSet.SELECT_TF_OPS | |
| ] | |
| # Optymalizacja pod kątem rozmiaru i stabilności | |
| converter.optimizations = [tf.lite.Optimize.DEFAULT] | |
| converter.target_spec.supported_types = [tf.float32] | |
| tflite_model = converter.convert() | |
| with open(TFLITE_OUTPUT_FILE, "wb") as f: | |
| f.write(tflite_model) | |
| print(f"✨ Model gotowy: {TFLITE_OUTPUT_FILE}") | |
| if __name__ == "__main__": | |
| convert() |