Metadata-Version: 2.4
Name: infx
Version: 1.12.0
Summary: infx：会猜、会死、会留下记忆的推理力模块；内含 look 子模块（看图并指出下一个点）
Author: My AI Knowledge Library
License-Expression: MIT
Project-URL: Homepage, https://github.com/codersd-githubpythoncv/infx
Project-URL: Source, https://github.com/codersd-githubpythoncv/infx
Project-URL: Documentation, https://github.com/codersd-githubpythoncv/infx/tree/main/docs
Project-URL: Changelog, https://github.com/codersd-githubpythoncv/infx/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/codersd-githubpythoncv/infx/issues
Keywords: reasoning,evolutionary,death,vision,rnn,lmm,patterns,numpy,pandas
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Provides-Extra: look
Requires-Dist: numpy>=1.24; extra == "look"
Requires-Dist: pandas>=2.0; extra == "look"
Requires-Dist: torch>=2.0; extra == "look"
Provides-Extra: vision
Requires-Dist: torch>=2.0; extra == "vision"
Provides-Extra: torch
Requires-Dist: torch>=2.0; extra == "torch"
Provides-Extra: math
Requires-Dist: scipy>=1.10; extra == "math"
Requires-Dist: sympy>=1.12; extra == "math"
Requires-Dist: mpmath>=1.3; extra == "math"
Provides-Extra: net
Requires-Dist: requests>=2.28; extra == "net"
Provides-Extra: crawl
Requires-Dist: requests>=2.28; extra == "crawl"
Requires-Dist: scrapling>=0.5; extra == "crawl"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Provides-Extra: all
Requires-Dist: numpy>=1.24; extra == "all"
Requires-Dist: pandas>=2.0; extra == "all"
Requires-Dist: torch>=2.0; extra == "all"
Requires-Dist: scipy>=1.10; extra == "all"
Requires-Dist: sympy>=1.12; extra == "all"
Requires-Dist: mpmath>=1.3; extra == "all"
Requires-Dist: requests>=2.28; extra == "all"
Requires-Dist: scrapling>=0.5; extra == "all"
Dynamic: license-file

# infx

**Build a model on your own machine: write layers, train them, and keep what it learned.**

`infx` has three parts, and they are meant to be used together:

1. **Build models** — `infx.nn` gives you `Linear`, `Embedding`, `Attention`,
   `LayerNorm`, `Sequential`, `Adam`, a training loop, and a real gradient checker.
   Every backward pass is hand-written and verified against finite differences.
2. **Remember** — `infx.create` saves what a model learned as a directory on disk,
   and `infx.look.Brain` keeps a probabilistic memory of what it has seen.
3. **Judge** — `infx` judges whether a sentence is a *fact* or an *opinion*, with an
   808-rule grammar base that can point to the exact rule behind a verdict.

No service, no API key, no GPU. numpy is the only hard dependency.

```bash
pip install infx                 # numpy + pandas
pip install "infx[torch]"        # optional: use real PyTorch modules instead
pip install "infx[math]"         # optional: sympy / mpmath / scipy verification
pip install "infx[net]"          # optional: verify against the web
```

```python
import infx
from infx.nn import Linear, Tanh, Sequential, Adam, train

model = Sequential([Linear(8, 32), Tanh(), Linear(32, 2)])
history = train(model, X, y, opt=Adam(model.parameters(), lr=0.05), epochs=40)
history.describe()      # 40 轮 · 损失 0.8979 → 0.0006 · 最好准确率 100.0%
```

---

## Build a model: `infx.nn`

This is the core. Layers with shapes you declare, gradients you can check.

```python
from infx.nn import Embedding, Attention, MeanPool, Linear, Sequential, gradcheck

net = Sequential([Embedding(50, 8), Attention(8, causal=True), MeanPool(), Linear(8, 2)])
net.check_shape(7)          # (7,) token ids → (2,) logits
gradcheck(net, ids, labels) # 参数 243 个 · 最大误差 8.5e-11 · 通过=True
```

| Layer | Does |
|---|---|
| `Linear(in, out)` | `y = xW + b`, Xavier-initialised |
| `Embedding(vocab, dim)` | id → vector, gradient scattered with `np.add.at` |
| `Attention(dim, causal=)` | single-head scaled dot-product, optional causal mask |
| `LayerNorm(dim)` | normalise the last axis, then scale and shift |
| `ReLU` / `Tanh` / `Dropout` | elementwise |
| `MeanPool()` | average over the sequence axis |
| `Sequential([...])` | runs layers, checks every shape transition |

`Adam` and `SGD` step the parameters. `train()` runs the loop and returns a
`History` with per-epoch loss and accuracy.

**Why a hand-written backward pass is worth it:** `gradcheck()` compares each
analytic gradient with a central difference. Measured agreement on this machine:
**8e-11 to 2e-10** across MLP, Embedding and Attention stacks. If a backward pass is
wrong, you find out in a test rather than from a model that quietly stops learning.

## Remember: models live on disk

```python
model = infx.create.classify(texts, labels, name="my-model")
model.score                 # 0.89 — mean over several hold-out splits
model.answer("这个设计很优雅")  # ('opinion', 1.0)
print(model.card())         # what it is, how it was made, what it scored
```

A model is a directory: `model.json`, `params.json`, `README.md`.
`create.list_models()` and `create.load(name)` manage them.

`infx.look.Brain` adds a different kind of memory: per-location probability tables
that keep learning from every image and report what they know as percentages.

## Judge: fact or opinion

```python
result = infx.assess("据新华社报道，温度达到 100 摄氏度。")
result.label.value, result.confidence      # ('fact', 0.83)
infx.speak(result)
```

808 rules (Chinese 532 / English 276, 26 kinds), each with a stable id, so a verdict
is traceable: `zh.src.900` is 「据新华社报道」.

## What it will not tell you

| It does not | Because |
|---|---|
| Beat PyTorch at speed or scale | cuBLAS and CUDA are another class of engineering |
| Fake a number | Scores are measured over several splits, with the spread recorded |
| Guess when it does not know | Thin evidence returns `unknown` plus the gap, never a confident guess |
| Pretend to be a service | Nothing is uploaded; models live in a directory you choose |

Docs: [quickstart](docs/quickstart.md) · [build a model](docs/create-a-model.md) ·
[architecture](docs/architecture.md) · [contributing](CONTRIBUTING.md)
