Local averaging summarizes nearby sequence values with a moving, weighted window. As a hardcoded convolution kernel, it smooths or exposes short patterns without training first. section 7.2.5
A pure Python implementation makes the operation concrete:
- Represent the sequence numerically, such as a binary indicator for whether each token is an adverb. section 7.2.5
- Choose kernel weights such as [0.5, 0.5] to average each adjacent pair. section 7.2.5
- Slide the kernel across the sequence, multiply corresponding values, and sum them; an input of length 20 produces 19 outputs. section 7.2.5
- Inspect the result as a smoothed signal: adjacent adverb indicators produce outputs of 0.5 or 1. section 7.2.5
Adverbness in a quotation
Part-of-speech tagging converts a quotation into an is-adverb sequence. Applying [0.5, 0.5] highlights neighboring adverb indicators, producing a local adverbness signal that can be plotted against the original input. section 7.2.5
Listing 7.4 Convolution in pure Python
>>> kernel = [.5, .5] #1
>>>
>>> output = []
>>> for i in range(len(inpt) - 1): #2
... z = 0
... for k, weight in enumerate(kernel): #3
... z = z + weight * inpt[i + k]
... output.append(z)
>>>
>>> print(f'inpt:\n{inpt}')
>>> print(f'len(inpt): {len(inpt)}')
>>> print(f'output:\n{[int(o) if int(o)==o else o for o in output]}')
>>> print(f'len(output): {len(output)}')inpt:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0., 1, 1., 0, 0, 0., 1., 0, 0, 0]
len(inpt): 20
output:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .5, 1, .5, 0, 0, .5, .5, 0, 0]
len(output): 19
Inspect the runnable pure Python convolution that defines the 2-point moving average and prints input and output lengths. section 7.2.5






