Saravanan666/pypi-org huggingface dataset:
Package: keras-bert-tpu
This is a fork ofCyberZHG/keras_bertwhich supports Keras BERT on TPU.Implementation of theBERT. Official pre-trained models could be loaded for feature extraction and prediction.Colab DemoHighCWu/keras-bert-tpuInstallpipinstallkeras-bert-tpuUsageLoad Official Pre-trained ModelsInfeature extraction demo, you should be able to get the same extraction result as the official model. And inprediction demo, the missing word in the sentence could be predicted.Train & Usefromkeras_bertimportget_base_dict,get_model,gen_batch_inputs# A toy input examplesentence_pairs=[[['all','work','and','no','play'],['makes','jack','a','dull','boy']],[['from','the','day','forth'],['my','arm','changed']],[['and','a','voice','echoed'],['power','give','me','more','power']],]# Build token dictionarytoken_dict=get_base_dict()# A dict that contains some special tokensforpairsinsentence_pairs:fortokeninpairs[0]+pairs[1]:iftokennotintoken_dict:token_dict[token]=len(token_dict)token_list=list(token_dict.keys())# Used for selecting a random word# Build & train the modelmodel=get_model(token_num=len(token_dict),head_num=5,transformer_num=12,embed_dim=25,feed_forward_dim=100,seq_len=20,pos_num=20,dropout_rate=0.05,)model.summary()def_generator():whileTrue:yieldgen_batch_inputs(sentence_pairs,token_dict,token_list,seq_len=20,mask_rate=0.3,swap_sentence_rate=1.0,)model.fit_generator(generator=_generator(),steps_per_epoch=1000,epochs=100,validation_data=_generator(),validation_steps=100,callbacks=[keras.callbacks.EarlyStopping(monitor='val_loss',patience=5)],)# Use the trained modelinputs,output_layer=get_model(# `output_layer` is the last feature extraction layer (the last transformer)token_num=len(token_dict),head_num=5,transformer_num=12,embed_dim=25,feed_forward_dim=100,seq_len=20,pos_num=20,dropout_rate=0.05,training=False,# The input layers and output layer will be returned if `training` is `False`)Custom Feature Extractiondef_custom_layers(x,trainable=True):returnkeras.layers.LSTM(units=768,trainable=trainable,name='LSTM',)(x)model=get_model(token_num=200,embed_dim=768,custom_layers=_custom_layers,)
Package: keras-bi-lm
Keras Bi-LMIntroductionThe repository contains a class for training a bidirectional language model that extracts features for each position in a sentence.Installpipinstallkeras-bi-lmUsageTrain and save the Bi-LM modelBefore using it as a feature extraction method, the language model must be trained on a large corpora.fromkeras_bi_lmimportBiLMsentences=[['All','work','and','no','play'],['makes','Jack','a','dull','boy','.'],]token_dict={'':0,'<UNK>':1,'<EOS>':2,'all':3,'work':4,'and':5,'no':6,'play':7,'makes':8,'a':9,'dull':10,'boy':11,'.':12,}token_dict_rev={v:kfork,vintoken_dict.items()}inputs,outputs=BiLM.get_batch(sentences,token_dict,ignore_case=True,unk_index=token_dict['<UNK>'],eos_index=token_dict['<EOS>'])bi_lm=BiLM(token_num=len(token_dict),embedding_dim=10,rnn_units=10)bi_lm.model.summary()bi_lm.fit(np.repeat(inputs,2**12,axis=0),[np.repeat(outputs[0],2**12,axis=0),np.repeat(outputs[1],2**12,axis=0),],epochs=5)bi_lm.save_model('bi_lm.h5')BiLM()The core class that contains the model to be trained and used. Key parameters:token_num: Number of words or characters.embedding_dim: The dimension of embedding layer.rnn_layer_num: The number of stacked bidirectional RNNs.rnn_units: An integer or a list representing the number of units of RNNs in one direction.rnn_keep_num: How many layers are used for predicting the probabilities of the next word.rnn_type: Type of RNN, 'gru' or 'lstm'.BiLM.get_batch()A helper function that converts sentences to batch inputs and outputs for training the model.sentences: A list of list of tokens.token_dict: The dict that maps a token to an integer.<UNK>and<EOS>should be preserved.ignore_case: Whether ignoring the case of the token.unk_index: The index for unknown token.eos_index: The index for ending of sentence.Load and use the Bi-LM modelfromkeras_bi_lmimportBiLMbi_lm=BiLM(model_path='bi_lm.h5')# or `bi_lm.load_model('bi_lm.h5')`input_layer,output_layer=bi_lm.get_feature_layers()model=keras.models.Model(inputs=input_layer,outputs=output_layer)model.summary()Theoutput_layeris the time-distributed feature and all the parameters in the layers of the model are not trainable.Use ELMo-like Weighted Sum of Trained Layersfromkeras_bi_lmimportBiLMbi_lm=BiLM(token_num=20000,embedding_dim=300,rnn_layer_num=3,rnn_keep_num=4,rnn_units=300,rnn_type='lstm',use_normalization=True)# ...# Train the Bi-LM model# ...input_layer,output_layer=bi_lm.get_feature_layers(use_weighted_sum=True)model=keras.models.Model(inputs=input_layer,outputs=output_layer)model.summary()Whenrnn_keep_numis greater thanrnn_layer_num, the embedding layer is also used for weighting.DemoSeedemodirectory:cddemo
./get_data.sh
pipinstall-rrequirements.txt
pythonsetiment_analysis.pyCitationJust cite the paper you've seen.
Package: keras-biological-gaps-sequence
Python package to generate on-hot encoded biological gaps to use for training and prediction.How do I install this package?As usual, just download it using pip:pipinstallkeras_biological_gaps_sequencesTests CoverageSince some software handling coverages sometimes
get slightly different results, here’s three of them:Available datasetsCurrently, there is only a dataset of gaps available
within the package: the mapping of known gaps from hg19
to hg38. In the future, we will be adding more mapping.Usage exampleTo use the sequence you can do as follows:biological_gap_sequence=BiologicalGapsSequence(source="hg19",target="hg38",source_window_size=1000,target_window_size=1000,batch_size=32)model=build_my_denoiser()model.fit_generator(biological_gap_sequence,steps_per_epoch=biological_gap_sequence.steps_per_epoch,epochs=2,shuffle=True)
Package: keras-bucket-tensorboard-callback
Keras Bucket Tensorboard CallbackA Keras Callback that uploads your Tensorboard logs to a Cloud BucketCurrently, only Google Cloud Platform Storage is supported. Very little effort
is needed to support AWS S3, so feel free to contribute to this project.Installationpipinstallkeras-bucket-tensorboard-callbackBasic usageThe following example trains uploads the Tensorboard logs to you GCP Storage
bucketmy-bucket, inside the directoryany_dir:# Import the classfromkeras_bucket_tensorboard_callbackimportBucketTensorBoard# Create the callback instance, passing the bucket URIbucket_callback=BucketTensorBoard('gs://my-bucket/any_dir')# Train the model with the callbackmodel.fit(x=X,y=Y,epochs=20,callbacks=[bucket_callback])Make sure you have access to the provided bucket. For GCP, you should have
theGOOGLE_APPLICATION_CREDENTIALSenv set, pointing to yourjsonkey
file.Viewing the results on TensorBoardWith tensorboard installed your environment, run:tensorboard--logdir=gs://my-bucket/any_dirThe TensorBoard will show your metrics and graphs saved on the bucket.
Package: keras-buoy
Keras wrapper that autosaves and auto-recovers not just the model weights but also the last epoch number and training history metrics.See it in action inthis Colab notebook!pip install keras-buoyDescriptionWhen training is interrupted and you rerun the whole code, it recovers the model weights and the epoch counter to the last saved values. Then it resumes training as if nothing happened. At the end, the Keras History.history dictionaries are combined so that the training history looks like one single training run.Example>>> from tensorflow import keras
>>> from keras_buoy.models import ResumableModel

>>> model = keras.Sequential()
...
>>> resumable_model = ResumableModel(model,
                                     save_every_epochs=4,
                                     custom_objects=None,
                                     to_path='/path/to/save/model_weights.h5')
>>> history = resumable_model.fit(x=x_train,
                                  y=y_train,
                                  validation_split=0.1,
                                  batch_size=256,
                                  verbose=2,
                                  epochs=15)

Recovered model from kerascheckpoint.h5 at epoch 8.

Epoch 9/15
1125/1125 - 5s - loss: 0.4790 - top_k_categorical_accuracy: 0.9698 - val_loss: 1.1075 - val_top_k_categorical_accuracy: 0.9206
Epoch 10/15
1125/1125 - 5s - loss: 0.4758 - top_k_categorical_accuracy: 0.9701 - val_loss: 1.1119 - val_top_k_categorical_accuracy: 0.9214
Epoch 11/15
1125/1125 - 5s - loss: 0.4753 - top_k_categorical_accuracy: 0.9702 - val_loss: 1.1000 - val_top_k_categorical_accuracy: 0.9215
Epoch 12/15Try it out yourself inthis Colab notebook.Docskeras_buoy.models.ResumableModelCreates a resumable model.Parameters:Parameter nameDescriptionmodel (tf.keras.Model)The instance oftf.keras.Modelwhich you want to make resumable.save_every_epochs (int)Specifies how often to save the model, history, and epoch counter.  In case of a crash, recovery will happen from the last saved epoch multiple.custom_objects (dict)At recovery time, this is passed intotf.keras.models.load_model(...)exactly as shown in Tensorflow docs so you can load your model with a custom loss for example.to_path (str)Specifies the path where the model weights will be saved. If it ends with.h5, then it saves in the Keras H5 format instead of the default TensorFlow SavedModel format.Ifto_pathismymodel.h5, then there will bemymodel_epoch_num.pklandmymodel_history.pklin the same directory asmymodel.h5, which hold backups for the epoch counter and the history dict, respectively.Returns:A ResumableModel instance. You can call.fit(...)on it.keras.buoy.models.ResumableModel.fitFits a resumable model.Parameters:The accepted parameters are the same astf.Keras.model.fit(...)except you cannot specifyinitial_epoch.Returns:history (dict): The history dict of the Keras History object. Note that it does not return theKeras.Historyobject itself, just the dict.NoteThis project has been set up using PyScaffold 3.2.3. For details and usage
information on PyScaffold seehttps://pyscaffold.org/.
Package: keras-callback-slack
keras_callback_slackkeras custom callback for slackInstallation$pipinstallkeras-callback-slackUsagefromkeras_callback_slackimportSlackNotificationsslack_notification=SlackNotifications('WEBHOOK_URL',token='TOKEN',channel='CHANNEL',attachment_image=True)model.fit(x,y,batch_size=64,epochs=5,callbacks=[slack_notification])Argumentsurl: string - Slack Incoming Webhook URLtoken: string(Optional) - Slack bot tokenThis will be needed when uploading the graph.channel: string(Optional) - Slack channel IDThe ID of the channel to which you want to upload the graph. Specify the same channel as the webhook.loss_metrics: list(Optional) - Loss metrics you want to monitor.ex.['loss', 'val_loss']acc_metrics: list(Optional) - Acc metrics you want to monitor.ex.['acc', 'val_acc']attachment_image: bool(Optional) - Whether to upload the graph.period: int(Optional) - Notification interval (epochs).Example
Package: keras_clinical
# keras-clinical
Keras Implemented Clinical Model Zoo## Purpose
To implement and expose relavent clinical models inkerasutilizing the familiarkeras.applicationsapi as a backbone.### Test Suit
All tests are located inkeras_clinical.tests### Installationpip install keras_clinical### Example` from keras_clinical.applications.grace_mortality import GRACE_MORTALITY gm = GRACE_MORTALITY() gm.summary() `
Package: keras-conv-visualizer
Keras Conv VisualizerPackage allows visualize convolutional layers from keras models.Table of contentsGeneral infoLibrariesSetupDocumentationPyPiTODODevelopmentStatusContactGeneral infoThis package is a set of tools for visualizing convolutional layers from keras models. At this moment includes:Filters visualizationGrad-CAM activation visualizationIntermediate activations visualizationLibrariesKeras - version 2.4.3Matplotlib - version 3.3.3NumPy - version 1.19.4OpenCV - version 4.4.0.46TensorFlow - version 2.4.0rc1SetupInstall from PyPi:pip install keras-conv-visualizerDocumentationStatus:in progressFilters visualizationimportmatplotlib.pyplotaspltfromtensorflow.keras.applicationsimportVGG16fromkeras_conv_visualizer.filtersimportFilterVisualization# Model has to have standarized input (std=0, var=1)!model=VGG16(weights="imagenet",include_top=False,input_shape=(224,224,3))layer_name="block5_conv3"# First parameter - trained keras model, second - input_sizefv=FilterVisualization(model)# First parameter - layer feature index (ex. block1_conv1 has (224, 224, 64) index is from 0 to 63)# Second parameter - layer nameloss,img=fv.visualize_filter(0,layer_name)plt.imshow(img)Result:Grad-CAM activation visualizationfromtensorflow.keras.preprocessing.imageimportload_img,img_to_arrayfromtensorflow.keras.applicationsimportVGG16,imagenet_utilsimportmatplotlib.pyplotaspltfromkeras_conv_visualizer.gradcamimportGradCAMimg_path='elephant.jpg'# load the input image from disk (in Keras/TensorFlow format) and preprocess itimage=load_img(img_path,target_size=(224,224))image=img_to_array(image)image=imagenet_utils.preprocess_input(image)model=VGG16(weights="imagenet",input_shape=(224,224,3))cam=GradCAM(model)# First parameter - image tensor, second - image path, third - alpha value for heatmap (transparency)heatmap,output=cam.make_superimposed_img(image,img_path,alpha=0.6)plt.imshow(heatmap)plt.imshow(output)Results:Input imageHeatmapSuperimposed imageIntermediate activations visualizationfromkeras.modelsimportload_modelfromkeras.preprocessingimportimagefromkeras_conv_visualization.intermediate_activationsimportIntermediateActivations# load the input image from disk (in Keras/TensorFlow format) and preprocess itimg=image.load_img('some_image.png',target_size=(96,96),color_mode='grayscale')img_tensor=image.img_to_array(img)img_tensor/=255model=load_model('some_model.h5')int_activations=IntermediateActivations(model)int_activations.plot_intermediate_activations(img_tensor)Input image:Results:PyPikeras-conv-visualizerTODOAdd shap valuesAutomatically recognition input size for FilterVisualizationDevelopmentWant to contribute? Great!To fix a bug or enhance an existing module, follow these steps:Fork the repoCreate a new branch (git checkout -b improve-feature)Make the appropriate changes in the filesVerify if they are correctAdd changes to reflect the changes madeCommit changesPush to the branch (git push origin improve-feature)Create a Pull RequestStatusLibrary is:in progressContactalbert.lis.1996@gmail.com- feel free to contact me!
Package: keras-cor
keras-cor : Correlated Outputs RegularizationAdd a regularization if the features/columns/neurons the hidden layer or output layer should be correlated. The vector with target correlation coefficient is computed before the optimization, and compared with correlation coefficients computed across the batch examples.UsageSeedemo notebookfromkeras_corimportCorrOutputsRegularizerimporttensorflowastf# Simple regression NNdefbuild_mymodel(input_dim,target_corr,cor_rate=0.1,activation="sigmoid",output_dim=3):inputs=tf.keras.Input(shape=(input_dim,))h=tf.keras.layers.Dense(units=output_dim)(inputs)h=tf.keras.layers.Activation(activation)(h)outputs=CorrOutputsRegularizer(target_corr,cor_rate)(h)# <= HEREmodel=tf.keras.Model(inputs=inputs,outputs=outputs)returnmodel# Gneerate toy datasetBATCH_SZ=128INPUT_DIM=64OUTPUT_DIM=3X_train=tf.random.normal([BATCH_SZ,INPUT_DIM])y_train=tf.random.normal([BATCH_SZ,OUTPUT_DIM])# Normally you should comput `target_corr` based on your target outputs `y_train`# e.g., target_corr = tf.constant(y_train)# However, you can also use subjective correlations (aka expert opinions), e.g.,target_corr=tf.constant([.5,-.4,.9])# Optimizationmodel=build_mymodel(input_dim=INPUT_DIM,target_corr=target_corr,output_dim=OUTPUT_DIM)model.compile(optimizer=tf.keras.optimizers.Adam(),loss="mean_squared_error")history=model.fit(X_train,y_train,verbose=1,epochs=2)# Inferenceyhat=model.predict(X_train)rhos=pearson_vec(yhat)rhosAppendixInstallationThekeras-corgit repois available asPyPi packagepipinstallkeras-cor
pipinstallgit+ssh://git@github.com/ulf1/keras-cor.gitInstall a virtual environmentpython3-mvenv.venvsource.venv/bin/activate
pipinstall--upgradepip
pipinstall-rrequirements.txt--no-cache-dir
pipinstall-rrequirements-dev.txt--no-cache-dir
pipinstall-rrequirements-demo.txt--no-cache-dir(If your git repo is stored in a folder with whitespaces, then don't use the subfolder.venv. Use an absolute path without whitespaces.)Python commandsJupyter for the examples:jupyter labCheck syntax:flake8 --ignore=F401 --exclude=$(grep -v '^#' .gitignore | xargs | sed -e 's/ /,/g')Run Unit Tests:PYTHONPATH=. pytestPublishpythonsetup.pysdisttwineupload-rpypidist/*Clean upfind.-typef-name"*.pyc"|xargsrm
find.-typed-name"__pycache__"|xargsrm-r
rm-r.pytest_cache
rm-r.venvSupportPleaseopen an issuefor support.ContributingPlease contribute usingGithub Flow. Create a branch, add commits, andopen a pull request.
Package: keras-core
Keras Core: A new multi-backend KerasKeras Core is a new multi-backend implementation of the Keras API, with support for TensorFlow, JAX, and PyTorch.WARNING:At this time, this package is experimental.
It has rough edges and not everything might work as expected.
We are currently hard at work improving it.Once ready, this package will become Keras 3.0 and subsumetf.keras.Local installationKeras Core is compatible with Linux and MacOS systems. To install a local development version:Install dependencies:pip install -r requirements.txtRun installation command from the root directory.python pip_build.py --installYou should also install your backend of choice:tensorflow,jax, ortorch.
Note thattensorflowis required for using certain Keras Core features: certain preprocessing layers as
well astf.datapipelines.Configuring your backendYou can export the environment variableKERAS_BACKENDor you can edit your local config file at~/.keras/keras.jsonto configure your backend. Available backend options are:"tensorflow","jax","torch". Example:export KERAS_BACKEND="jax"In Colab, you can do:importosos.environ["KERAS_BACKEND"]="jax"importkeras_coreaskerasNote:The backend must be configured before importingkeras_core, and the backend cannot be changed after
the package has been imported.Backwards compatibilityKeras Core is intended to work as a drop-in replacement fortf.keras(when using the TensorFlow backend). Just take your
existingtf.kerascode, change thekerasimports tokeras_core, make sure that your calls tomodel.save()are using
the up-to-date.kerasformat, and you're done.If yourtf.kerasmodel does not include custom components, you can start running it on top of JAX or PyTorch immediately.If it does include custom components (e.g. custom layers or a customtrain_step()), it is usually possible to convert it
to a backend-agnostic implementation in just a few minutes.In addition, Keras models can consume datasets in any format, regardless of the backend you're using:
you can train your models with your existingtf.data.Datasetpipelines or PyTorchDataLoaders.Why use Keras Core?Run your high-level Keras workflows on top of any framework -- benefiting at will from the advantages of each framework,
e.g. the scalability and performance of JAX or the production ecosystem options of TensorFlow.Write custom components (e.g. layers, models, metrics) that you can use in low-level workflows in any framework.You can take a Keras model and train it in a training loop written from scratch in native TF, JAX, or PyTorch.You can take a Keras model and use it as part of a PyTorch-nativeModuleor as part of a JAX-native model function.Make your ML code future-proof by avoiding framework lock-in.As a PyTorch user: get access to power and usability of Keras, at last!As a JAX user: get access to a fully-featured, battle-tested, well-documented modeling and training library.
Package: keras-cortex
Keras :brain: CortexKeras Implementations of Goal-driven models of (parts of) cortexCurrently Supported Architectures:eye: Visual CortexArchitecturePaperOriginal ImplementationCORNetZhttps://www.biorxiv.org/content/10.1101/408385v1https://github.com/dicarlolab/CORnetCORNetShttps://papers.nips.cc/paper/2019/hash/7813d1590d28a7dd372ad54b5d29d033-Abstract.htmlhttps://github.com/dicarlolab/CORnet
Package: keras-crf
keras-crfA more elegant and convenient CRF built on tensorflow-addons.Python Compatibility is limited totensorflow/addons, you can check the compatibility from it's home page.Installationpipinstallkeras-crfUsageHere is an example to show you how to build a CRF model easily:importtensorflowastffromkeras_crfimportCRFModel# build backbone model, you can use large models like BERTsequence_input=tf.keras.layers.Input(shape=(None,),dtype=tf.int32,name='sequence_input')outputs=tf.keras.layers.Embedding(21128,128)(sequence_input)outputs=tf.keras.layers.Dense(256)(outputs)base=tf.keras.Model(inputs=sequence_input,outputs=outputs)# build CRFModel, 5 is num of tagsmodel=CRFModel(base,5)# no need to specify a loss for CRFModel, model will compute crf loss by itselfmodel.compile(optimizer=tf.keras.optimizers.Adam(3e-4)metrics=['acc'],)model.summary()# you can now train this modelmodel.fit(dataset,epochs=10,callbacks=None)The model summary:Model:"crf_model"__________________________________________________________________________________________________
Layer(type)OutputShapeParam#     Connected to==================================================================================================sequence_input(InputLayer)[(None,None)]0__________________________________________________________________________________________________
embedding(Embedding)(None,None,128)2704384sequence_input[0][0]__________________________________________________________________________________________________
dense(Dense)(None,None,256)33024embedding[0][0]__________________________________________________________________________________________________
crf(CRF)[(None,None),(None1320dense[0][0]__________________________________________________________________________________________________
decode_sequence(Lambda)(None,None)0crf[0][0]__________________________________________________________________________________________________
potentials(Lambda)(None,None,5)0crf[0][1]__________________________________________________________________________________________________
sequence_length(Lambda)(None,)0crf[0][2]__________________________________________________________________________________________________
kernel(Lambda)(5,5)0crf[0][3]==================================================================================================Totalparams:2,738,728
Trainableparams:2,738,728
Non-trainableparams:0__________________________________________________________________________________________________
Package: keras-data-format-converter
Keras data format converterGenerates equal keras models with the desired data formatRequirementstensorflow >= 2.0APIconvert_channels_first_to_last(model: keras.Model, inputs_to_transpose: List[str] = None, verbose: bool = False) -> keras.Modelconvert_channels_last_to_first(model: tf.keras.Model, inputs_to_transpose: List[str] = None, verbose: bool = False) \ -> tf.keras.Modelmodel: Keras model to convertinputs_to_transpose: list of input names that need to be transposed due tothe data foramt changingverbose: detailed outputGetting startedfromtensorflowimportkerasfromkeras_data_format_converterimportconvert_channels_last_to_first# Load Keras modelkeras_model=keras.models.load_model("my_image_model")# Call the converter (image_input is an input that needs to be transposed, can be different for your model)converted_model=convert_channels_last_to_first(keras_model,["image_input"])Supported Layers with Special handlingNormalization layersPermuteReshapeConcatenateDotMultiHeadAttentionTFOpLambda (Inserted by the Functional API construction whenever users call
a supported TF symbol on KerasTensors, seehereat Tensorflow repo for more info)Unsupported Layers due to lack of data_format propertyCropping1DUpsampling1DZeropadding1DAll layers in tensorflow.keras.preprocessingHow to deployCreate a new release version on GitHubUpdate parameters in setup.py (usuallyversionanddownload_url)Runpython setup.py sdistin root directoryRunpip install twineRuntwine upload dist/*LicenseThis software is covered by MIT License.