Source-linked AI summary
ktrain: A Low-Code Library for Augmented Machine Learning
Arun S. Maiya
TL;DR
Machine-learning workflows are difficult for newcomers because they involve specialized preprocessing, configuration, inspection, and deployment steps. ktrain addresses this with a unified low-code interface spanning multiple data types and model choices, and the paper demonstrates workflows implemented in as little as three lines of code. The library is intended to help beginners, domain experts, and experienced practitioners build or prototype machine-learning models with minimal coding.
Problem
Machine-learning workflows require specialized preprocessing, hyperparameter selection, inspection, and deployment steps that can be challenging for newcomers.
Method
ktrain provides a unified Python interface for preprocessing data, configuring or selecting models, training, inspecting, and applying models across supported tasks.
Results
ktrain supports text, vision, graph, and tabular tasks, with the open-domain question-answering example producing the correct answer “October of 1997” in three lines of code.
Takeaways & Limitations
ktrain offers a low-code toolbox for beginners and domain experts while remaining flexible for custom models and data formats and useful for rapid prototyping.
Abstract
from arXiv · showhide
We present ktrain, a low-code Python library that makes machine learning more accessible and easier to apply. As a wrapper to TensorFlow and many other libraries (e.g., transformers, scikit-learn, stellargraph), it is designed to make sophisticated, state-of-the-art machine learning models simple to build, train, inspect, and apply by both beginners and experienced practitioners. Featuring modules that support text data (e.g., text classification, sequence tagging, open-domain question-answering), vision data (e.g., image classification), graph data (e.g., node classification, link prediction), and tabular data, ktrain presents a simple unified interface enabling one to quickly solve a wide range of tasks in as little as three or four "commands" or lines of code.
1. Introduction
ktrain addresses the complexity of building, inspecting, and deploying machine-learning workflows with a unified low-code interface. It supports diverse text, vision, graph, and tabular tasks, while allowing users to select state-of-the-art or custom models.
- Workflow challenges: Machine-learning workflows require data-format handling, task-specific preprocessing, hyperparameter selection, model inspection, and production deployment.These requirements span model building, inspection, and executing preprocessing together with models on new data.
- Low-code interface: ktrain provides a unified interface that can perform these workflow steps in as little as three or four lines of code.The library supports models implemented in TensorFlow Keras.
- Text tasks: Supported text tasks include classification, regression, sequence tagging, topic modeling, document similarity, recommendation, and summarization.These tasks cover supervised, unsupervised, extraction, similarity, and retrieval-style text applications.
- Vision, graph, and tabular tasks: Supported multimodal tasks include open-domain question-answering, image classification and regression, graph node classification and link prediction, and tabular classification, regression, and causal inference.The examples include answering questions from large text corpora, categorizing images, predicting image values, and predicting graph links.
- Model choices and tooling: Users can choose state-of-the-art models or custom models, including Transformer models such as BERT and faster text models such as fastText and NB-SVM.Additional capabilities include learning-rate tools, modern optimizers, Explainable AI inspection, prediction APIs, and pretrained NER models.
2. Augmented ML
ktrain frames augmented machine learning as workflow automation that complements rather than replaces human engineers. It targets domain experts and others who need assistance across the full machine-learning process while retaining application-specific choices.
- Augmented ML: Unlike traditional AutoML, ktrain emphasizes automating or semi-automating workflow steps beyond architecture search and model selection.Its scope includes curating and preprocessing inputs, training, tuning, troubleshooting, and applying models.
- Human augmentation: ktrain combines well-performing defaults with user choices so domain experts can apply machine learning without extensive coding or machine-learning experience.The stated design uses automation to augment and complement human engineers rather than replace them.
3. Building Models
ktrain organizes supervised model building through a unified workflow for loading data, creating models, selecting learning rates, and training across different data types. The same interface supports automatic configuration and similar steps for text and image classification.
- Workflow: ktrain’s supervised workflow loads and preprocesses data before model creation, with preprocessing adapted to text, images, or graphs.Text may require tokenization, images may require pixel normalization, and graphs may require compiling node and link attributes.
- Model creation: Users can select pre-canned models or customize models with tf.keras, while ktrain wraps the model and datasets in a Learner instance.Pre-canned options include pretrained BERT classifiers, sequence-tagging models, and pretrained ResNets; model settings can be inferred from the data.
- Training configuration: Learning-rate range tests can estimate an appropriate learning rate, although this step is optional for models such as BERT with effective defaults.The learning-rate finder is applied to the chosen model and data.
- Training configuration: ktrain supports multiple training schedules, including 1cycle, triangular schedules with automatic early stopping, and cosine annealing.The autofit method can reduce the maximum learning rate upon plateau, while fit can decay the rate each cycle.
- Examples: The Chinese sentiment-analysis example uses the same low-code workflow as the image-classification example despite their different data types.The examples cover hotel-review sentiment classification and Dogs vs. Cats image classification with a pretrained ResNet50.
- Examples: For Chinese text, language and encoding are detected automatically, and the model is configured from inferred target properties such as class count and label structure.The configuration distinguishes mutually exclusive categories and numerical versus categorical targets.
4. Evaluating and Applying Models
ktrain provides interfaces for evaluating, inspecting, explaining, and applying trained models. Its Predictor bundles the model with preprocessing and can be saved for later deployment.
- Evaluating and inspecting: ktrain’s evaluate method computes validation or test metrics, while view_top_losses identifies examples on which the model performs worst.The example output includes precision, recall, and F1-score reports for individual classes.
- Applying models: A Predictor combines the underlying model with its preprocessing steps to transform raw inputs and generate predictions on unseen data.Predictor instances can be saved and reloaded for production deployments.
- Applying models: Predictors can be saved and reloaded, preserving the components needed to apply the model after deployment.The prediction API supports creating a predictor, making predictions, saving it, and loading it again.
- Explaining models: For some text- and image-classification tasks, the explain method uses SHAP and eli5 with LIME to illuminate why a decision was made.The explanations can address both successful and unsuccessful decisions.
5. Non-Supervised ML Tasks
ktrain extends its low-code interface to non-supervised tasks such as open-domain question answering. A three-line workflow indexes documents, retrieves relevant contexts, extracts candidate answers, and returns the highest-confidence result.
- Open-domain question answering: Open-domain question answering indexes a corpus, retrieves documents containing question terms, extracts contexts, and identifies candidate answers with a pretrained BERT model.Candidate answers are sorted and pruned by confidence scores before results are returned.
- Low-code interface: ktrain applies a low-code API to non-supervised tasks even when their pipelines differ from the supervised workflow.The paper presents end-to-end open-domain question answering as an example of this broader support.
- Open-domain question answering: The complete QA workflow can be implemented with a minimal low-code API using SimpleQA and an initialized search index.The example creates a SimpleQA object, initializes an index, and indexes documents from a list.
6. Conclusion
The paper presents ktrain as a low-code platform supporting text, vision, graph, and tabular machine learning through a TensorFlow Keras wrapper. It targets both beginners and domain experts while also supporting rapid prototyping by experienced practitioners.
- Conclusion: ktrain supports model training on text, vision, graph, and tabular data through a low-code platform.It wraps TensorFlow Keras and includes out-of-the-box support across these data types.
- Conclusion: The platform is intended to help beginners and domain experts build sophisticated models with minimal coding or data-science experience.Its stated aim is to further democratize machine learning.
- Conclusion: ktrain also serves experienced practitioners who need to rapidly prototype deep-learning solutions.This use case complements its accessibility goals for less experienced users.
Appendix A. Loading the 20 Newsgroups Dataset
The example loads the 20 Newsgroups Dataset into a Python list using scikit-learn, while removing headers, footers, and quotes.
- The 20 Newsgroups Dataset is loaded using scikit-learn's fetch_20newsgroups function.
- The dataset is loaded into a Python list for subsequent processing.
- Headers, footers, and quotes are removed from the dataset.
Appendix B. Open-Domain Question-Answering Example
The question-answering example displays results in a Jupyter notebook, including a correctly identified Cassini launch date and its source context.
- ktrain includes a screenshot showing results from its question-answering API in a Jupyter notebook.
- The qa.display method formats and displays answers within a Jupyter notebook.
- The top candidate correctly identifies October 1997 as the Cassini space probe's launch date.The answer is highlighted within its source context.
- The displayed results include the list index of the newsgroup posting containing the answer.This index is shown because the documents were indexed with index_from_list.
Appendix C. Additional Low-Code ML Examples
The appendix demonstrates ktrain's low-code interface across graph, topic-modeling, zero-shot classification, and named-entity-recognition tasks, including examples requiring no labeled training data.
- Additional low-code examples: The examples cover supervised and non-supervised machine-learning tasks to illustrate ktrain's ease of use.
- Named Entity Recognition with BioBERT embeddings: Named entity recognition is illustrated with BioBERT embeddings using token sequences and corresponding entity labels.The data are converted with entities_from_array, and training uses a learning rate of 0.01 for one epoch with cycle_len=5.
- Node Classification with Graph Neural Networks: Node classification with graph neural networks is presented as a ktrain task.The example imports ktrain's graph module and follows data-loading, model, learning-rate, and training steps.
- Node Classification with Graph Neural Networks: The graph example trains a model with autofit using a triangular learning-rate schedule and early stopping.
- Theme Discovery: Theme discovery requires no labeled training examples and builds semantically meaningful document vectors before printing topics.
- Theme Discovery: The recommender is trained as a Nearest Neighbors model and produces five thematic-similarity suggestions for input text.
- Zero-Shot Topic Classification: Zero-shot topic classification requires no labeled training examples and assigns the example document high scores for politics and elections.The reported scores are 0.9829 for politics and 0.9881 for elections.