扫码阅读
手机扫码阅读

Keras 3.0强势回归,动手学深度学习(上)

40 2024-10-10

我们非常重视原创文章,为尊重知识产权并避免潜在的版权问题,我们在此提供文章的摘要供您初步了解。如果您想要查阅更为详尽的内容,访问作者的公众号页面获取完整文章。

查看原文:Keras 3.0强势回归,动手学深度学习(上)
文章来源:
AI科技论谈
扫码关注公众号
Keras 3.0 Practical Tips Summary

Summary of Practical Tips for Keras 3.0

1. Framework Installation and Environment Configuration

Installing Keras 3.0 is straightforward following the official guide. Prior to Keras, it's recommended to install Pytorch matching the CUDA version, either 11.8 or 12.1, based on graphics driver support. By default, Keras installs TensorFlow 2.16.1, which might trigger a missing CUDA warning if Pytorch is used as the backend. To suppress unnecessary TensorFlow logs, set the 'TF_CPP_MIN_LOG_LEVEL' environment variable to '2'.

To configure Keras to use Pytorch as the backend, one can either modify the keras.json configuration file or set an environment variable. The keras.json usually resides in ~/.keras/ or C:\Users\Your_User\\.keras\ on Windows. Post-installation, if the .keras directory is missing, importing Keras in IPython or Jupyter Notebook should locate it. Then, change the "backend" key to "torch" in keras.json or set the "KERAS_BACKEND" environment variable to "torch". Confirm the backend switch by querying keras.config.backend().

2. End-to-End Project Implementation

Using a neural machine translation (NMT) model, this section walks through using the subclassing API in Keras 3.0. NMT models are encoder-decoder architectures, often based on LSTM RNNs, which translate source text embeddings to target languages. Target texts are offset by one step and start with an SOS placeholder, ending with an EOS to mark the sequence's end. The architecture can be visualized in a flowchart for clarity.

For practical project execution, it's beneficial to import all necessary libraries at the project's beginning. This simplifies the process of adding missing libraries later. An example is shown for importing packages like pathlib, pickle, keras, layers, utils, and numpy. Setting a random seed across Python, Numpy, and Pytorch for reproducibility is also a useful tip.

Data preparation is crucial, and the project uses a Spanish-English dataset from the Tatoeba project. This dataset is manageable in size, allowing for direct reading with numpy's genfromtxt function. After verifying the data, the actual project practice can begin.

Recommended Reading

The book "Keras Deep Learning Development in Practice" is suggested for those seeking an in-depth understanding of deep learning with Keras, covering topics from data sets and cleaning to model evaluation, including regularization techniques, convolutional neural networks, transfer learning, and recurrent neural networks. Purchase link provided.

Highlights Revisited

Previous articles on PyTorch for NLP, advanced PyTorch tips, liquid neural networks, free tools for running large models locally, and comparisons between LlamaIndex and LangChain are recapped.

想要了解更多内容?

查看原文:Keras 3.0强势回归,动手学深度学习(上)
文章来源:
AI科技论谈
扫码关注公众号