NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning Visual N-Grams from Web Data

Ang Li, Allan Jabri, Armand Joulin, Laurens van der Maaten

Abstract

Real-world image recognition systems need to recognize tens of thousands of classes that constitute a plethora of visual concepts. The traditional approach of annotating thousands of images per class for training is infeasible in such a scenario, prompting the use of webly supervised data. This paper explores the training of image-recognition systems on large numbers of images and associated user comments, without using manually labeled images. In particular, we develop visual n-gram models that can predict arbitrary phrases that are relevant to the content of an image. Our visual n-gram models are feed-forward convolutional networks trained using new loss functions that are inspired by n-gram models commonly used in language modeling. We demonstrate the merits of our models in phrase prediction, phrase-based image retrieval, relating images and captions, and zero-shot transfer.

Introduction: The Open-World Challenge

Traditional computer vision models typically operate in a "closed-world" setting, where they are trained to recognize a pre-defined set of classes—such as the 1,000 categories in ImageNet—using thousands of manually annotated examples per class. However, the real world is "open-world." Visual concepts range from generic objects like "dog" to highly specific landmarks, events, and nuanced phrases.

An example of a complex visual concept found in web data, illustrating the need for open-world recognition.

Manually labeling enough data for every possible phrase is impossible. While the internet provides a nearly infinite supply of images with user comments (weakly supervised data), this data is noisy and follows a "long-tail" distribution. This research aims to bridge the gap between vision and language by learning directly from unstructured web data.

Methodology: Visual N-Grams and J-M Loss

The proposed Visual N-Gram models are feed-forward Convolutional Neural Networks (specifically a 34-layer ResNet) that assign a likelihood to any given phrase (n-gram) based on an image's content.

The core technical innovation is the Jelinek-Mercer (J-M) loss function. In traditional language modeling, "smoothing" handles rare phrases by backing off to shorter, more frequent sub-phrases. The authors transformed this concept into a differentiable loss function for end-to-end training. This approach effectively handles the long tail of web data and enables out-of-vocabulary prediction by combining the probabilities of known sub-grams.

Experimental Setup

The models were trained on the YFCC100M dataset, specifically a filtered subset of 30 million images with English user comments. The vocabulary consisted of 142,806 n-grams (unigrams to five-grams) appearing at least 1,000 times. Evaluation was conducted across several benchmarks, including the YFCC100M test set for phrase prediction, COCO-5K and Flickr-30K for image-caption retrieval, and ImageNet for zero-shot transfer.

Key Results and Discussion

The research demonstrates that moving from unigrams (single words) to n-grams (phrases) allows the model to resolve visual ambiguity. For instance, the model can distinguish between "Washington State" (landscapes) and "Washington DC" (monuments).

Recall@k performance across different n-gram orders.

Key quantitative findings include:

  • Phrase Prediction: The Jelinek-Mercer model achieved 42.0% accuracy in human-rated phrase relevance, outperforming ImageNet-based baselines (32.7%).
  • Zero-Shot Transfer: Despite no formal labels, the model achieved 35.2% top-1 accuracy on ImageNet classes present in its dictionary.
  • Performance Scaling: As shown in the figure above, higher-order n-gram models consistently outperform unigram models in recall, validating the importance of phrase-level context.

Conclusion

This work suggests that the sheer scale of web data can compensate for the lack of clean manual labels. By incorporating language modeling smoothing techniques into the training loss, visual n-gram models can learn a much broader visual vocabulary than traditional supervised systems. Future work may explore more complex smoothing techniques like Kneser-Ney and applications in Visual Question Answering (VQA).

Summary updated

BibTeX
@inproceedings{li2017learning,
  author = {Ang Li and Allan Jabri and Armand Joulin and Laurens van der Maaten},
  title = {{Learning Visual N-Grams from Web Data}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2017},
  url = {https://openreview.net/forum?id=HyNboeGdZB},
}
Figure