ktrain: A Low-Code Library for Augmented Machine Learning

Arun S. Maiya

article2022JMLR170 citations

Presents an open-source Python library that wraps TensorFlow and Hugging Face Transformers to train, inspect, and deploy state-of-the-art machine learning models across text, vision, graph, and tabular domains using only a few lines of code.

Listen

Building and deploying modern machine learning models often presents steep technical barriers for organizations. Standard workflows require complex, multi-step engineering for data preprocessing, hyperparameter optimization, model diagnosis, and deployment packaging. While automated machine learning tools attempt to automate model discovery, they often overlook practical workflow pain points, leaving non-expert domain specialists and rapid-prototyping teams constrained by high coding overhead.

The article introduces and evaluates ktrain, an open-source, low-code Python library designed to streamline end-to-end machine learning workflows. Its core objective is to demonstrate how a unified, simplified interface can allow both novice practitioners and experienced engineers to build, train, inspect, and deploy sophisticated machine learning models in as few as three or four lines of code.

The author demonstrates the library's utility through concrete implementations across supervised and non-supervised domains, including fine-tuning deep neural networks for non-English text classification and constructing open-domain question-answering pipelines. Built as a wrapper around established frameworks such as TensorFlow Keras, Hugging Face Transformers, and scikit-learn, the library automates routine engineering steps while incorporating human-in-the-loop inspection and model tuning techniques. The article also benchmarks the platform's out-of-the-box feature coverage against major existing low-code and automated machine learning frameworks.

The findings establish that the library significantly simplifies end-to-end execution across four primary data modalities: text, vision, graph, and tabular data. First, the framework automates key preprocessing requirements, such as language detection, character encoding, and data normalization, eliminating bespoke boilerplate code. Second, it wraps complex supervised training workflows—including optimal learning rate estimation, learning rate scheduling, and early stopping—into a standard four-step template. Third, it enables non-supervised and multi-stage systems, such as building a document search and retrieval question-answering system over thousands of text records, using as few as three commands. Finally, a comparative feature analysis shows that the library provides broader out-of-the-box support for advanced natural language processing tasks (such as semantic search and zero-shot learning) and graph-based models than competing frameworks like fastai, Ludwig, AutoKeras, and AutoGluon.

These capabilities indicate that organizations can substantially reduce the time, labor cost, and technical friction required to build and test advanced artificial intelligence solutions. By abstracting lower-level implementation details while retaining the flexibility of custom deep learning models, the library lowers barriers for domain experts and accelerates rapid prototyping cycles. Furthermore, integrated model inspection and explainability tools assist teams in managing deployment risks and evaluating model reliability before production.

Organizations aiming to accelerate machine learning delivery should evaluate open-source, low-code augmented frameworks like ktrain for pilot projects, particularly for text-heavy and graph-structured applications. Technical leaders should encourage teams to test these tools for initial prototyping before committing heavy engineering resources to bespoke pipelines. Because the article focuses on feature availability and qualitative workflow demonstrations rather than formal empirical benchmarks comparing predictive accuracy or system throughput across libraries, technical teams should conduct internal performance and latency testing to validate that low-code implementations meet production performance standards.

Cover for ktrain: A Low-Code Library for Augmented Machine Learning

Abstract

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.

Table of Contents

  • 1. Introduction
  • 2. Building Models
  • 3. Non-Supervised ML Tasks
  • 4. Comparison to Related Libraries
  • 5. Conclusion
  • References

Knowls

  1. Knowl 1 — Augmented machine learning focuses on automating workflow support

    definition

    The paper uses augmented machine learning for an approach that partially or fully automates workflow tasks such as data preprocessing, model tuning with human involvement, and model inspection. This distinguishes ktrain’s emphasis from AutoML systems that focus strongly on automating model-building choices such as architecture search. ktrain is a low-code Python interface built around TensorFlow Keras and other machine-learning libraries, intended to make building, training, inspecting, and applying models accessible through only a few commands.

  2. Knowl 2 — Supervised learning follows a unified four-stage workflow

    model/method

    For supervised tasks, ktrain organizes work into a common sequence: (1) load and preprocess task-specific data; (2) create a custom TensorFlow Keras model or select a supplied model, then wrap the model and datasets in a ktrain.Learner; (3) optionally estimate a learning rate using a range test; and (4) train with a selected training method and learning-rate schedule. The learning-rate estimation stage is optional when a model has a suitable default, as the paper notes for BERT. This shared pattern is intended to work across data types including text, images, and graphs.

  3. Knowl 3 — Preprocessors carry training-time transformations into prediction

    model/method

    ktrain preprocessing methods return a Preprocessor object that encapsulates the transformations used for a particular task. The same object can be used when applying the trained model to new, unseen data, keeping prediction inputs consistent with the model’s expected representation. Examples of preprocessing include language-specific text tokenization, model-specific image pixel normalization, and compiling node and link attributes for graph tasks.

  4. Knowl 4 — Supplied models can be configured from inspected data

    model/method

    When a user selects a pre-canned model, ktrain can inspect the data and configure the model for its target structure. The inspection can determine the number of categories, whether a classification problem is mutually exclusive or multilabel, and whether targets are numerical or categorical. The paper presents this automatic configuration as a way to avoid requiring users to manually supply these task details for supported models.

  5. Knowl 5 — Training utilities provide learning-rate search and multiple schedules

    model/method

    ktrain provides several training controls through its Learner interface. lr_find runs a learning-rate range test to help estimate a suitable rate. fit_onecycle trains with the 1cycle policy. autofit uses a triangular learning-rate schedule, applies automatic early stopping, and reduces the maximum learning rate when performance plateaus, so a fixed epoch count is optional. The fit method can use cosine annealing when supplied with cycle_len. These options let users try different schedules for a problem; the paper does not report a comparative performance evaluation of the schedules.

  6. Knowl 6 — Inspection and prediction support the model lifecycle beyond training

    model/method

    The ktrain workflow includes facilities for inspecting model behavior and applying a trained model. For classification, the paper identifies validation classification reports and ways to surface examples the model gets most wrong; it also describes access to Explainable AI methods for investigating errors. For application, ktrain provides a prediction API and is designed to keep the preprocessing steps needed for new raw inputs available alongside model use. These capabilities support human review and deployment in addition to model fitting.

  7. Knowl 7 — The library offers task-specific models alongside custom TensorFlow Keras models

    model/method

    ktrain supports custom models implemented in TensorFlow Keras as well as supplied models with defaults. Examples given in the paper include BERT for text classification, fastText and NBSVM as text-classification options suitable for training on a standard laptop CPU, sequence-tagging models, and pretrained Residual Networks for image classification. The library also includes ready-to-use named-entity-recognition models for English, Chinese, and Russian. Its stated out-of-the-box scope spans text, vision, graph, and tabular data.

  8. Knowl 8 — Chinese BERT sentiment classification demonstrates the supervised interface

    experimental setup

    The paper demonstrates supervised training on Chinese hotel reviews using a BERT text classifier. The example loads training and validation data from a folder with texts_from_folder, sets maxlen=75 and preprocess_mode='bert', creates a BERT classifier, and wraps it with a Learner. It then invokes lr_find and trains with fit_onecycle using a learning rate of 2×10−52\times10^{-5} for 4 epochs. The paper states that language and character encoding are detected automatically, so the example does not require a separate Chinese-specific workflow. It reports no classification metric for this demonstration.

  9. Knowl 9 — SimpleQA combines search with pretrained answer extraction

    model/method

    ktrain’s SimpleQA builds an open-domain question-answering system over a document collection. The workflow indexes the documents in a search engine, retrieves documents containing terms from a question, extracts paragraphs from them as contexts, applies a BERT model pretrained on SQuAD to produce candidate answers, and sorts and prunes candidates using confidence scores. The paper’s example uses the 20 Newsgroups documents as the knowledge base. Documents can be supplied as a Python list or indexed from a folder when the collection is too large for a list.

  10. Knowl 10 — The reported task-coverage comparison highlights ktrain’s NLP and graph support

    data/table

    The paper compares out-of-the-box task support in ktrain, fastai, Ludwig, AutoKeras, and AutoGluon. Its matrix indicates that all five support tabular and image classification/regression and text classification/regression, while ktrain has entries for a broad range of additional NLP tasks and both listed graph tasks. The table is a feature-availability comparison, not a performance benchmark. In the matrix, prefitted* means a pre-fine-tuned model can be applied without training; question-answering models marked with an asterisk can be used without training or further fine-tuned.

    Data and taskktrainfastaiLudwigAutoKerasAutoGluon
    Tabular: Classification/Regression✓✓✓✓✓
    Tabular: Causal Machine Learning✓
    Tabular: Time Series Forecasting✓✓
    Tabular: Collaborative Filtering✓
    Image: Classification/Regression✓✓✓✓✓
    Image: Object Detectionprefitted*✓✓
    Image: Image Captioningprefitted*✓
    Image: Segmentation✓
    Image: GANs✓
    Image: Keypoint/Pose Estimation✓
    Audio: Classification/Regression✓
    Audio: Speech Transcriptionprefitted*✓
    Text: Classification/Regression✓✓✓✓✓
    Text: Sequence-Tagging✓✓
    Text: Unsupervised Topic Modeling✓
    Text: Semantic Search✓
    Text: End-to-End Question-Answering✓*
    Text: Zero-Shot Learning✓
    Text: Language Translationprefitted*✓
    Text: Summarizationprefitted*✓
    Text: Text Extraction✓
    Text: QA-Based Information Extraction✓*
    Text: Keyphrase Extraction✓
    Graph: Node Classification✓
    Graph: Link Prediction✓

Coverage note — No substantial contributed material was omitted. The paper provides illustrative code examples but no quantitative model-performance evaluation; the examples’ substantive workflows and settings are captured here.

References

  1. 1.CSIRO’s Data61. Stellargraph machine learning library. https://github.com/stellargraph/stellargraph, 2018.
  2. 2.Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805, 2018.
  3. 3.Nick Erickson, Jonas Mueller, Alexander Shirkov, Hang Zhang, Pedro Larroy, Mu Li, and Alexander Smola. Autogluon-tabular: Robust and accurate automl for structured data. arXiv preprint arXiv:2003.06505, 2020.
  4. 4.Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. arXiv preprint arXiv:1512.03385, 2015.
  5. 5.Xin He, Kaiyong Zhao, and Xiaowen Chu. Automl: A survey of the state-of-the-art. arXiv preprint arXiv:1908.00709, 2019.
  6. 6.Jeremy Howard and Sylvain Gugger. Fastai: A layered api for deep learning. Information, 11(2):108, Feb 2020. ISSN 2078-2489. doi: 10.3390/info11020108. URL http://dx.doi.org/10.3390/info11020108.
  7. 7.Haifeng Jin, Qingquan Song, and Xia Hu. Auto-keras: An efficient neural architecture search system. arXiv preprint arXiv:1806.10282, 2019.
  8. 8.Armand Joulin, Edouard Grave, Piotr Bojanowski, and Tomas Mikolov. Bag of tricks for efficient text classification. arXiv preprint arXiv:1607.01759, 2016.
  9. 9.Guillaume Lample, Miguel Ballesteros, Sandeep Subramanian, Kazuya Kawakami, and Chris Dyer. Neural architectures for named entity recognition. arXiv preprint arXiv:1603.01360, 2016.
  10. 10.Ilya Loshchilov and Frank Hutter. Sgdr: Stochastic gradient descent with warm restarts. arXiv preprint arXiv:1608.03983, 2016.
  11. 11.Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. arXiv preprint arXiv:1711.05101, 2017.
  12. 12.Piero Molino, Yaroslav Dudin, and Sai Sumanth Miryala. Ludwig: a type-based declarative deep learning toolbox. arXiv preprint arXiv:1909.07930, 2019.
  13. 13.F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay. Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12:2825–2830, 2011.
  14. 14.Leslie N. Smith. A disciplined approach to neural network hyper-parameters: Part 1 – learning rate, batch size, momentum, and weight decay. arXiv preprint arXiv:1803.09820, 2018.
  15. 15.Sida Wang and Christopher D. Manning. Baselines and bigrams: Simple, good sentiment and topic classification. In Proceedings of the 50th Annual Meeting of the Association for Computational Linguistics: Short Papers - Volume 2, ACL ’12, page 90–94, USA, 2012. Association for Computational Linguistics.
  16. 16.Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pierric Cistac, Tim Rault, Rémi Louf, Morgan Funtowicz, and Jamie Brew. Huggingface’s transformers: State-of-the-art natural language processing. arXiv preprint arXiv:1910.03771, 2019.

Citation

MLA
Maiya, A. S. “Ktrain: A Low-Code Library for Augmented Machine Learning”. Journal of Machine Learning Research, vol. 23, no. 158, 2022, pp. 1–6, https://www.jmlr.org/papers/v23/21-1124.html.
APA
Maiya, A. S. (2022). ktrain: A Low-Code Library for Augmented Machine Learning. Journal of Machine Learning Research, 23(158), 1–6. https://www.jmlr.org/papers/v23/21-1124.html
Chicago
Maiya, A. S. 2022. “Ktrain: A Low-Code Library for Augmented Machine Learning”. Journal of Machine Learning Research 23 (158): 1–6. https://www.jmlr.org/papers/v23/21-1124.html.
Harvard
Maiya, A.S. (2022) “ktrain: A Low-Code Library for Augmented Machine Learning”, Journal of Machine Learning Research, 23(158), pp. 1–6. Available at: https://www.jmlr.org/papers/v23/21-1124.html.
Vancouver
1. Maiya AS (2022) ktrain: A Low-Code Library for Augmented Machine Learning. Journal of Machine Learning Research 23:1–6

BibTeX

@article{JMLR:v23:21-1124,
  author  = {Arun S. Maiya},
  title   = {ktrain: A Low-Code Library for Augmented Machine Learning},
  journal = {Journal of Machine Learning Research},
  year    = {2022},
  volume  = {23},
  number  = {158},
  pages   = {1--6},
  url     = {http://jmlr.org/papers/v23/21-1124.html}
}
Metadata:DOI registry

Source Code

This paper has an official code repository available. Click below to access the source code.

View Repository

Access the Paper

This paper is available from its original source. Click below to access the PDF.

Open PDF
License: https://creativecommons.org/licenses/by/4.0/