Jump to content

File:1-skip-2-gram.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia
Original file (SVG file, nominally 960 × 288 pixels, file size: 48 KB)

Summary

Description
English: diagram for 1-skip-2-gram

Matplotlib code

import numpy as np
import matplotlib.pyplot as plt

# Example sentence
words = ["the", "rain", "in", "Spain", "falls", "mainly", "on", "the", "plain"]
positions = np.arange(len(words))

fig, ax = plt.subplots(figsize=(10, 3))
ax.set_ylim(-1.2, 1.2)
ax.set_xlim(-0.5, len(words) - 0.5)
ax.axis('off')

# Plot words
for x, w in zip(positions, words):
    ax.text(x, 0, w, ha='center', va='center')

# Parameters for curve offset and amplitude
offset_top = 0.4
offset_bottom = -0.4
amplitude = 0.6

# Draw curves for bigrams (2-grams) on top
for i in range(len(words) - 1):
    j = i + 1
    t = np.linspace(0, 1, 100)
    xs = positions[i] + t * (positions[j] - positions[i])
    ys = offset_top + amplitude * np.sin(np.pi * t)
    ax.plot(xs, ys, color='black')

# Draw curves for 1-skip-2-grams on bottom
for i in range(len(words) - 2):
    j = i + 2
    t = np.linspace(0, 1, 100)
    xs = positions[i] + t * (positions[j] - positions[i])
    ys = offset_bottom - amplitude * np.sin(np.pi * t)
    ax.plot(xs, ys, color='black')

plt.tight_layout()
# plt.show()
plt.savefig('skip-gram.svg')

Date
Source Own work
Author Cosmia Nebula

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

8 May 2025

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current22:55, 8 May 2025Thumbnail for version as of 22:55, 8 May 2025960 × 288 (48 KB)Cosmia NebulaUploaded while editing "Word n-gram language model" on en.wikipedia.org

The following 2 pages use this file:

Metadata