Saravanan666/pypi-org huggingface dataset:
Package: keras-tqdm
Keras integration with TQDM progress bars.Kerasis an awesome machine learning library for Theano or TensorFlow.TQDMis a progress bar library with good support for nested loops and Jupyter/IPython notebooks.Key featuresTQDM supports nested progress bars. If you have Keras fit and
predict loops within an outer TQDM loop, the nested loops will
display properly.TQDM supports Jupyter/IPython notebooks.TQDM looks great!TQDMNotebookCallbackwithleave_inner=False(default)TQDMNotebookCallbackwithleave_inner=TrueTQDMCallbackfor command-line scriptsInstallationStable releasepip install keras-tqdmDevelopment releasepip install git+https://github.com/bstriner/keras-tqdm.git --upgrade --no-depsDevelopment mode (changes to source take effect without reinstalling)git clone https://github.com/bstriner/keras-tqdm.git
cd keras-tqdm
python setup.py developBasic usageIt’s very easy to use Keras TQDM. The only required change is to remove default messages (verbose=0) and add a callback tomodel.fit. The rest happens automatically! For Jupyter Notebook required code modification is as simple as:from keras_tqdm import TQDMNotebookCallback
# keras, model definition...
model.fit(X_train, Y_train, verbose=0, callbacks=[TQDMNotebookCallback()])For plain text mode (e.g. for Python run from command line)from keras_tqdm import TQDMCallback
# keras, model definition...
model.fit(X_train, Y_train, verbose=0, callbacks=[TQDMCallback()])Advanced usageUsekeras_tqdmto utilize TQDM progress bars for Keras fit loops.keras_tqdmloops can be nested inside TQDM loops to display nested progress bars (although you can use them
inside ordinary for loops as well).
Setverbose=0to suppress the default progress bar.from keras_tqdm import TQDMCallback
from tqdm import tqdm
for model in tqdm(models, desc="Training several models"):
    model.fit(x, y, verbose=0, callbacks=[TQDMCallback()])For IPython and Jupyter notebookTQDMNotebookCallbackinstead ofTQDMCallback. Usetqdm_notebookin your own code instead oftqdm.
Formatting is controlled by python format strings. The defaultmetric_formatis"{name}: {value:0.3f}".
For example, useTQDMCallback(metric_format="{name}:{value:0.6f}")for 6 decimal points or{name}: {value:e}for scientific notation.Questions?Please feel free to submit PRs and issues. Comments, questions, and
requests are welcome. If you need more control, subclassTQDMCallbackand override thetqdmfunction.
Package: keras-transformer-xl
Keras Transformer-XL[中文|English]Unofficial implementation ofTransformer-XL.Installpipinstallkeras-transformer-xlUsageLoad Pretrained WeightsSeveral configuration files can be found atthe info directory.importosfromkeras_transformer_xlimportload_trained_model_from_checkpointcheckpoint_path='foo/bar/sota/enwiki8'model=load_trained_model_from_checkpoint(config_path=os.path.join(checkpoint_path,'config.json'),checkpoint_path=os.path.join(checkpoint_path,'model.ckpt'))model.summary()About IOThe generated model has two inputs, and the second input is the lengths of memories.You can useMemorySequencewrapper for training and prediction:fromtensorflowimportkerasimportnumpyasnpfromkeras_transformer_xlimportMemorySequence,build_transformer_xlclassDummySequence(keras.utils.Sequence):def__init__(self):passdef__len__(self):return10def__getitem__(self,index):returnnp.ones((3,5*(index+1))),np.ones((3,5*(index+1),3))model=build_transformer_xl(units=4,embed_dim=4,hidden_dim=4,num_token=3,num_block=3,num_head=2,batch_size=3,memory_len=20,target_len=10,)seq=MemorySequence(model=model,sequence=DummySequence(),target_len=10,)model.predict(model,seq,verbose=True)
Package: keras-trans-mask
Keras Transfer MaskingRemove and restore masks for layers that do not support masking. Note that the result may be incorrect in most cases.Installpipinstallkeras-trans-maskUsageConv1Ddoes not support masking. By removing the mask you'll get a "nearly correct" output:fromtensorflowimportkerasfromkeras_trans_maskimportRemoveMask,RestoreMaskinput_layer=keras.layers.Input(shape=(None,))embed_layer=keras.layers.Embedding(input_dim=10,output_dim=15,mask_zero=True,)(input_layer)removed_layer=RemoveMask()(embed_layer)# Remove mask from embeddingsconv_layer=keras.layers.Conv1D(filters=32,kernel_size=3,padding='same',)(removed_layer)restored_layer=RestoreMask()([conv_layer,embed_layer])# Restore mask from embeddingslstm_layer=keras.layers.LSTM(units=5)(restored_layer)dense_layer=keras.layers.Dense(units=2,activation='softmax')(lstm_layer)model=keras.models.Model(inputs=input_layer,outputs=dense_layer)model.compile(optimizer='adam',loss='sparse_categorical_crossentropy')model.summary()
Package: keras-tuner
KerasTunerKerasTuner is an easy-to-use, scalable hyperparameter optimization framework
that solves the pain points of hyperparameter search. Easily configure your
search space with a define-by-run syntax, then leverage one of the available
search algorithms to find the best hyperparameter values for your models.
KerasTuner comes with Bayesian Optimization, Hyperband, and Random Search algorithms
built-in, and is also designed to be easy for researchers to extend in order to
experiment with new search algorithms.Official Website:https://keras.io/keras_tuner/Quick linksGetting started with KerasTunerKerasTuner developer guidesKerasTuner API referenceInstallationKerasTuner requiresPython 3.8+andTensorFlow 2.0+.Install the latest release:pip install keras-tunerYou can also check out other versions in ourGitHub repository.Quick introductionImport KerasTuner and TensorFlow:importkeras_tunerfromtensorflowimportkerasWrite a function that creates and returns a Keras model.
Use thehpargument to define the hyperparameters during model creation.defbuild_model(hp):model=keras.Sequential()model.add(keras.layers.Dense(hp.Choice('units',[8,16,32]),activation='relu'))model.add(keras.layers.Dense(1,activation='relu'))model.compile(loss='mse')returnmodelInitialize a tuner (here,RandomSearch).
We useobjectiveto specify the objective to select the best models,
and we usemax_trialsto specify the number of different models to try.tuner=keras_tuner.RandomSearch(build_model,objective='val_loss',max_trials=5)Start the search and get the best model:tuner.search(x_train,y_train,epochs=5,validation_data=(x_val,y_val))best_model=tuner.get_best_models()[0]To learn more about KerasTuner, check outthis starter guide.Contributing GuidePlease refer to theCONTRIBUTING.mdfor the contributing guide.Thank all the contributors!CommunityAsk your questions on ourGitHub Discussions.Citing KerasTunerIf KerasTuner helps your research, we appreciate your citations.
Here is the BibTeX entry:@misc{omalley2019kerastuner,title={KerasTuner},author={O'Malley, Tom and Bursztein, Elie and Long, James and Chollet, Fran\c{c}ois and Jin, Haifeng and Invernizzi, Luca and others},year=2019,howpublished={\url{https://github.com/keras-team/keras-tuner}}}
Package: keras-tuner-cv
Keras Tuner Cross ValidationExtension for keras tuner that adds a set of classes to implement cross validation methodologies.Install$ pip install keras_tuner_cvImplemented methodologiesHere is the list of implemented methodologies and how to use them!Outer Cross Validationfromkeras_tuner_cv.outer_cvimportOuterCVfromkeras_tuner.tunersimportRandomSearchfromsklearn.model_selectionimportKFoldcv=KFold(n_splits=5,random_state=12345,shuffle=True),outer_cv=OuterCV(# You can use any class extendind:# sklearn.model_selection.cros.BaseCrossValidatorcv,# You can use any class extending:# keras_tuner.engine.tuner.Tuner, e.g. RandomSearchRandomSearch,# Tuner parameters both positional and named ones...)Inner Cross Validationfromkeras_tuner_cv.outer_cvimportOuterCVfromkeras_tuner.tunersimportRandomSearchfromsklearn.model_selectionimportKFoldcv=KFold(n_splits=5,random_state=12345,shuffle=True),# You can use any class extending:# keras_tuner.engine.tuner.Tuner, e.g. RandomSearchouter_cv=inner_cv(RandomSearch)(hypermodel,# You can use any class extendind:# sklearn.model_selection.cros.BaseCrossValidatorcv,# Tuner positional parameters except hypermodel...,# Saves the history of all metrics observed across the epochs# in json format.save_history=False,# Saves the model output for both the training and validation# datasets in numpy format.save_output=False,# Indicates when or not to reload the best weights w.r.t. to# the objective indicated for the calculation of output and# scores.restore_best=True,# Tuner named parameters except hypermodel...)LicenseKeras Tuner CV is released under theGPL v3.
Package: kerastuner-tensorboard-logger
Keras-tuner Tensorboard loggerkeras-tunerlogger for streaming search report toTensorboard plugins Hparams, beautiful interactive visualization tool.RequirementsPython 3.6+keras-tuner 1.0.0+Tensorboard 2.1+Installation$ pip install kerastuner-tensorboard-loggerExamplehere is simple (and incomplete) code.See details about how to use keras-tunerhere.Add only one argument in tuner class and search it, then you can go to see search report in Tensorboard.Optionally, you can callsetup_tbto be more accurate TensorBoard visualization. It convert keras-tuner hyperparameter information and doTensorboard experimental setup.# import thisfromkerastuner_tensorboard_loggerimport(TensorBoardLogger,setup_tb# Optional)tuner=Hyperband(build_model,objective="val_acc",max_epochs=5,directory="logs/tuner",project_name="tf_test",logger=TensorBoardLogger(metrics=["val_acc"],logdir="logs/hparams"),# add only this argument)setup_tb(tuner)# (Optional) For more accurate visualization.tuner.search(x,y,epochs=5,validation_data=(val_x,val_y))Tensorboard$tensorboard--logdir./logs/hparamsGo tohttp://127.0.0.1:6006.You will see the interactive visualization (provided by Tensorboard).
Package: keras-tweaks
keras-tweaksUtility functions for Keras/Tensorflow2.InstallationThekeras-tweaksgit repois available asPyPi packagepipinstallkeras-tweaks# pip install git+ssh://git@github.com/ulf1/keras-tweaks.gitUsageID Sequence to Bool Maskimporttensorflowastffromkeras_tweaksimportidseqs_to_maskidseqs=[[1,1,0,0,2,2,3],[1,3,2,1,0,0,2]]masks=idseqs_to_mask(idseqs,n_seqlen=6,ignore=[1],dtype=tf.uint8,dense=False)print(tf.sparse.to_dense(masks))SeeexampleMultiply row vector with sparse matrixPlease check the notebooks foran
exampleandan
explanationimporttensorflowastffromkeras_tweaksimportdense_sparse_matmul# 1x3 row vectorh=tf.constant([1.,2.,3.])# 3x4 sparse matrixW=tf.sparse.SparseTensor(indices=([0,1],[1,1],[1,2],[2,0],[2,2],[0,3],[2,3]),values=[1.,2.,3.,4.,5.,6.,7.],dense_shape=(3,4))W=tf.sparse.reorder(W)# result is a 1x4 row vectornet=dense_sparse_matmul(h,W)Sparsity Patterns for KerasTheblock-diagonal pattern for tensorflowimporttensorflowastffromkeras_tweaksimportget_sparsity_patternn_rows,n_cols=10,12mat_pattern=get_sparsity_pattern('block',min(n_rows,n_cols),block_sizes=[3,1,2])mat_values=range(1,len(mat_pattern)+1)mat=tf.sparse.SparseTensor(dense_shape=(n_rows,n_cols),indices=mat_pattern,values=mat_values)print(tf.sparse.to_dense(mat))Please, check thehowto.ipynb of the sparsity-pattern
packagefor more sparsity patterns. Thekeras_tweaks.get_sparsity_patternmethod works exactly the same.AppendixInstall a virtual environmentpython3 -m venv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install -r requirements.txt --no-cache-dir
pip3 install -r requirements-dev.txt --no-cache-dir
pip3 install -r requirements-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:pytestPublishpandocREADME.md--frommarkdown--torst-s-oREADME.rstpythonsetup.pysdisttwineupload-rpypidist/*Clean upfind . -type f -name "*.pyc" | xargs rm
find . -type d -name "__pycache__" | xargs rm -r
rm -r .pytest_cache
rm -r .venvLicense and citationThe functionkeras_tweaks.get_sparsity_patternis a wrapper for
the python packagesparsity-patternwhat
is also licensed under Apache License 2.0. If you are using the
function, and like to cite thesparsity-patternpackage, then use
the DOI:10.5281/zenodo.4357290SupportPleaseopen an
issuefor support.ContributingPlease contribute usingGithub
Flow. Create a branch,
add commits, andopen a pull
request.
Package: keras-unsupervised
Keras UnsupervisedKeras framework based unsupervised learning frameworkOn Keras, to develop semi-supervised learning and unsupervised learning via backpropagation, Keras framework based unsupervised learning libraries are necessary. For this reason, we focus on developing EBM (Energy based model) unsupervised learning modules, and autoencoder and GAN (Generative Adversarial Networks) modules which are based on unsupervised learning via backpropagation, and Keras layers and Tensorflow and Tensorflow-probability backend interfaces for unsupervied learning, and relevant utils. As a symbolic computation backend, Tensorflow is only applied.TasksPlain RBM, DBN.GAN, Style-based GAN.AutoEncoder.First release, documentation.BM, DBM.Convolutional RBM, DBN.Second release, documentation.Tasks statusGAN and Autoencoder are being tested.
Package: keras-util
Set of simple helpers for KerasSome functions that should be included inKerasfor user convenience but are too small and forgotten.Example:Keras training history visualizationimportkeras_utilasuhistory=model.fit(..)u.plot_history(history)fig,axs=plt.subplots(4,1)custom_axs=[axs[1],axs[3]]u.plot_history(history,custom_axs)
Package: keras-utils
Keras UtilsThis package provides utilities for Keras, such as modified callbacks, genereators, etc.InstallationTo install the package from the PyPi repository you can execute the following
command:pipinstallkeras-utilsUsageThe usage of the package is simple:importkerasimportkeras_utils# build your modelmodel=get_model(input_shape,num_classes=num_classes,reserve_layers=reserve_layers)# build your train-set & validation-set generatorstrain_generator=ImageDataGenerator().flow_from_directory(train_images_path,target_size=target_size,batch_size=batch_size,color_mode='rgb',class_mode='categorical',seed=seed,shuffle=True)valid_generator=ImageDataGenerator().flow_from_directory(valid_images_path,target_size=target_size,batch_size=1,color_mode='rgb',class_mode='categorical',shuffle=False)# create a validation-callback which tests the validation-set every 10 epocksvalid_callback=ValidateCallback(10,valid_generator,model)# create a save-callback which saves the model every 20 epochs under the name "model_name"save_callback=SaveCallback(20,'model_name.model',model)# train your modelmodel.fit_generator(generator=train_generator,epochs=epochs,verbose=1,workers=8,callbacks=[valid_callback,save_callback])
Package: keras-video-generators
Keras Sequence Video generatorsThis package proposes some classes to work with Keras (included in TensorFlow) that generates batches of frames from video files.It is useful to work with Time Distributed Layer with Video input (frames). Then you may use GRU or LSTM.
See articles:The basics of Video frame as inputUsage of these generators hereAn provided example of usage can bedisplayed in nbviewer here.Requirements are:Python >= 3.6 (Python 2 will never been supported)OpenCVnumpyKeras >= 2TensorFlow >= 1.15 (or other backend, not tested, TensorFlow is needed by Keras)TensorFlow 2 works as well. This requirementsis not integrated in the setup.pyto let you choose the version, or to let you try with other backend. We mean that you will need to install a backend yourself (e.g.pip install tensorflow)If you want to compile the package, you need:sphinx to compile doc (work in progress)setuptoolsInstallationYou can install the package viapip:pipinstallkeras-video-generatorsIf you want to build from sources, clone the repository then:pythonsetup.pybuildUsageThe package contains 3 generators that inheritsSequenceinterface. So they may be used withmodel.fit_generator():VideoFrameGeneratorthat will take the choosen number of frames from the entire videoSlidingFrameGeneratorthat takes frames with decay for the entire video or with a sequence timeOpticalFlowGeneratorthat gives optical flow sequence from frames with different methods (experimental)Each of these generators accepts parameters:glob_patternthat must contain{classname}, e.g. './videos/{classname}/*.avi' - the "classname" in string is used to detect classesnb_framesthat is the number of frame in the sequencebatch_sizethat is the number of sequence in one batchtransformationthat can beNoneor or ImageDataGenerator to make data augmentationuse_frame_cacheto use with caution, if set toTrue, the class will keep frames in memory (without augmentation). You needa lot of memoryand many more, see class documentationChangelogv1.0.14Changes to get first and last frames in sequencev1.0.13try to fix SageMaker problem by avoiding usage of internal keras from tensorflowv1.0.12fix transformation error with SlidingFrameGeneratorv1.0.11set generator to be Iterableframe cache was disabled by error, it's back nowfixup import Sequence fromtensorflow.kerasfix frame count problems for video with bad headersv1.0.10fix Windows problems with path using backslashesadd auto discovery for classes if "None" is sentadd travis testsv1.0.9fix frame counter in SlidingFrameGeneratorv1.0.8fix tiny video frame countrefactorisationpep8fix problems for video without headersv1.0.7fix name check in classes to get them from filenameaddsplit_testandsplit_valv1.0.5fix package generationv1.0.4fix assertion
Package: keras-webhook-callback
Keras Notification CallbackA Keras callback which sends information about your model training, on various messaging platforms.InstallationUsingpip:pipinstallkeras-webhook-callbackUsageImport the required module and add it to the list callbacks while training your model.Example:>>>fromkeras_webhook_callbackimportTelegramCallback>>>telegram_callback=TelegramCallback('<BotToken>','<ChatID>','CNN Model',['loss','val_loss'],['accuracy','val_accuracy'],True)>>>model.fit(x_train,y_train,batch_size=32,epochs=10,validation_data=(x_test,y_test),callbacks=[telegram_callback])TelegramCreate a telegram bot using BotFatherSearch for @BotFather on telegram.Send/helpto get list of all commands.Send/newbotto create a new bot and complete the setup.Copy thebot tokenafter creating the bot.Get thechat IDSearch for the bot you created and send it any random message.Go to this URLhttps://api.telegram.org/bot<BOT_TOKEN>/getUpdates(replace <BOT_TOKEN> with your bot token)Copy thechat idof the user you want to send messages to.Use theTelegramCallback()class.TelegramCallback(bot_token=None,chat_id=None,modelName='model',loss_metrics=['loss'],acc_metrics=[],getSummary=False):Arguments:bot_token: unique token of Telegram bot{str}chat_id: Telegram chat id you want to send message to{str}modelName: name of your model{str}loss_metrics: loss metrics you want in the loss graph{list of strings}acc_metrics: accuracy metrics you want in the accuracy graphs{list of strings}getSummary: Do you want message for each epoch (False) or a single message containing information about all epochs (True).{bool}SlackCreate a Slack workspaceCreate a new channelSearch for theIncoming Webhooksin the Apps and install it.Copy theWebhook URLUse theSlackCallback()class.SlackCallback(bot_token=None,chat_id=None,modelName='model',loss_metrics=['loss'],acc_metrics=[],getSummary=False):Arguments:webhookURL: unique webhook URL of the app{str}channel:  channel name or username you want to send message to{str}modelName: name of your model{str}loss_metrics: loss metrics you want in the loss graph{list of strings}acc_metrics: accuracy metrics you want in the accuracy graph{list of strings}getSummary: Do you want message for each epoch (False) or a single message containing information about all epochs (True).{bool}Sending images in Slack is not supported currently.ToDoWhatsAppE-MailZulipMessagesMotivationAs the Deep Learning models are getting more and more complex and computationally heavy, they take a very long time to train. During my internship, people used to start the model training and left it overnight. They could only check its progress the next day. So I thought it would be great if there was a simple way to get the training info remotely on their devices.
Package: keras-xlnet
Keras XLNetLicense[中文|English]Unofficial implementation ofXLNet.Embedding extractionandembedding extract with memoryshow how to get the outputs of the last transformer layer using pre-trained checkpoints.Installpipinstallkeras-xlnetUsageFine-tuning on GLUEClick the task name to see the demos with base model:Task NameMetricsApproximate Results on Dev SetCoLAMatthew Corr.52SST-2Accuracy93MRPCAccuracy/F186/89STS-BPearson Corr. / Spearman Corr.86/87QQPAccuracy/F190/86MNLIAccuracy84/84QNLIAccuracy86RTEAccuracy64WNLIAccuracy56(Only 0s are predicted in WNLI dataset)Load Pretrained Checkpointsimportosfromkeras_xlnetimportTokenizer,load_trained_model_from_checkpoint,ATTENTION_TYPE_BIcheckpoint_path='.../xlnet_cased_L-24_H-1024_A-16'tokenizer=Tokenizer(os.path.join(checkpoint_path,'spiece.model'))model=load_trained_model_from_checkpoint(config_path=os.path.join(checkpoint_path,'xlnet_config.json'),checkpoint_path=os.path.join(checkpoint_path,'xlnet_model.ckpt'),batch_size=16,memory_len=512,target_len=128,in_train_phase=False,attention_type=ATTENTION_TYPE_BI,)model.summary()Argumentsbatch_size,memory_lenandtarget_lenare maximum sizes used for initialization of memories. The model used for training a language model is returned ifin_train_phaseisTrue, otherwise a model used for fine-tuning will be returned.About I/ONote thatshuffleshould beFalsein eitherfitorfit_generatorif memories are used.in_train_phaseisFalse3 inputs:IDs of tokens, with shape(batch_size, target_len).IDs of segments, with shape(batch_size, target_len).Length of memories, with shape(batch_size, 1).1 output:The feature for each token, with shape(batch_size, target_len, units).in_train_phaseisTrue4 inputs:IDs of tokens, with shape(batch_size, target_len).IDs of segments, with shape(batch_size, target_len).Length of memories, with shape(batch_size, 1).Masks of tokens, with shape(batch_size, target_len).1 output:The probability of each token in each position, with shape(batch_size, target_len, num_token).
Package: kerasy
KerasyI want todeepen my understanding of deep learningby imitating the sophisticated neural networks API,Keras.InstallationThere are two ways to install Kerasy:Install Kerasy from PyPI (recommended):$ sudo pip install kerasyAlternatively: install Kerasy from the GitHub source:$ git clone https://github.com/keras-team/keras.git
$ cd keras
$ sudo python setup.py installWhy this name KerasyKerasy means “Keras” + “-y”.Kerasis a high-level neural networks API, written in Python.“-y” is a native English suffix of adjectives meaning“characterized by or inclined to”the substance or action of the word or stem to which the suffix is attached. It often plays a role like“ish”,“esque”, or“like”.Keras is my favorite library, so I wanted to imitate it and add more algorithms for in particular bioinformatics (which is my major.)KerasKeras is a high-level neural networks API, written in Python and capable of running on top ofTensorFlow,CNTK, orTheano. It was developed with a focus on enabling fast experimentation.Being able to go from idea to result with the least possible delay is key to doing good research.