A perceptron turns numerical inputs into a decision. Inspired by biological neurons, it multiplies each input by a weight, adds the results and a bias, then applies an activation function. Weights control how sensitive the output is to each input; the bias shifts the decision point. section 5.1.3 section 5.1.5
A step activation gives a binary result: output 1 when the weighted sum exceeds a threshold, and 0 otherwise. A sigmoid activation instead gives a continuous value and makes the calculation resemble logistic regression. The weighted sum alone is linear; the activation adds a nonlinear step. section 5.1.4 section 5.1.5
>>> from collections import Counter >>> np.random.seed(451) >>> tokens = "green egg egg ham ham ham spam spam spam spam".split() >>> bow = Counter(tokens) >>> x = pd.Series(bow) >>> x green 1 egg 2 ham 3 spam 4 >>> x1, x2, x3, x4 = x >>> x1, x2, x3, x4 (1, 2, 3, 4) >>> w0 = np.round(.1 * np.random.randn(), 2) >>> w0 0.07 >>> w1, w2, w3, w4 = (.1 * np.random.randn(len(x))).round(2) >>> w1, w2, w3, w4 (0.12, -0.16, 0.03, -0.18) >>> x = np.array([1, x1, x2, x3, x4]) #1 >>> w = np.array([w0, w1, w2, w3, w4]) #2 >>> y = np.sum(w * x) #3 >>> y -0.76
Follow a Python forward pass using bag-of-words counts of 1, 2, 3, and 4. The untrained weights and bias produce a weighted sum of −0.76; a zero-threshold step would output 0. section 5.1.5
For language inputs, a tokenizer can turn text into word counts or TF-IDF features. The perceptron assigns a weight to each feature. Training seeks weights that improve predictions, using a loss function to measure error; a forward pass alone does not train the model. section 5.1.4 section 5.1.5
Predicting a birth-certificate label from a name
A single neuron can use characters in first names to predict recorded sex labels, with about 80% accuracy reported for the example. That label is not a definitive property of a name or a person: names can have multiple labels, and binary categories oversimplify sex. section 5.2.2




