Skip to content

Commit c07bf53

Browse files
Include docs in the main repository
1 parent 3343faa commit c07bf53

24 files changed

+2152
-0
lines changed

.github/workflows/docs.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy Docs site to Pages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: false
17+
18+
jobs:
19+
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0 # Not needed if lastUpdated is not enabled
27+
28+
- name: Setup Bun
29+
uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
30+
31+
- name: Setup Pages
32+
uses: actions/configure-pages@v4
33+
34+
- name: Navigate to docs directory
35+
run: cd docs
36+
37+
- name: Install dependencies
38+
run: bun install
39+
40+
- name: Build with VitePress
41+
run: bun run docs:build
42+
43+
- name: Upload artifact
44+
uses: actions/upload-pages-artifact@v3
45+
with:
46+
path: .vitepress/dist
47+
48+
deploy:
49+
environment:
50+
name: github-pages
51+
url: ${{ steps.deployment.outputs.page_url }}
52+
needs: build
53+
runs-on: ubuntu-latest
54+
name: Deploy
55+
steps:
56+
- name: Deploy to GitHub Pages
57+
id: deployment
58+
uses: actions/deploy-pages@v4

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@
5151
"scripts": {
5252
"test": "vendor/bin/pest",
5353
"test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage"
54+
},
55+
"archive": {
56+
"exclude": ["/docs"]
5457
}
5558
}

docs/.gitignore

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
### OSX ###
2+
# General
3+
.DS_Store
4+
.AppleDouble
5+
.LSOverride
6+
7+
# Thumbnails
8+
._*
9+
10+
11+
# Files that might appear in the root of a volume
12+
.DocumentRevisions-V100
13+
.fseventsd
14+
.Spotlight-V100
15+
.TemporaryItems
16+
.Trashes
17+
.VolumeIcon.icns
18+
.com.apple.timemachine.donotpresent
19+
.idea
20+
21+
# Directories potentially created on remote AFP share
22+
.AppleDB
23+
.AppleDesktop
24+
Network Trash Folder
25+
Temporary Items
26+
.apdisk
27+
28+
### Node ###
29+
# Logs
30+
logs
31+
*.log
32+
npm-debug.log*
33+
yarn-debug.log*
34+
yarn-error.log*
35+
lerna-debug.log*
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
41+
# dotenv environment variables file
42+
.env
43+
.env.test
44+
45+
# vitepress build output
46+
.vitepress/dist
47+
.vitepress/cache

docs/.vitepress/config.mts

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import {defineConfig} from 'vitepress'
2+
3+
// https://vitepress.dev/reference/site-config
4+
export default defineConfig({
5+
title: "Transformers PHP",
6+
description: "State-of-the-art Machine Learning for PHP. Run Transformers in PHP",
7+
base: "/transformers-docs/",
8+
themeConfig: {
9+
// https://vitepress.dev/reference/default-theme-config
10+
nav: [
11+
{text: 'Home', link: '/'},
12+
{text: 'Docs', link: '/docs/'},
13+
{
14+
text: '0.1.x',
15+
items: [
16+
{
17+
text: 'Changelog',
18+
link: 'https://github.com/CodeWithKyrian/transformers-php/blob/main/CHANGELOG.md'
19+
},
20+
{
21+
text: 'Contributing',
22+
link: 'https://github.com/CodeWithKyrian/transformers-php/blob/main/.github/contributing.md'
23+
},
24+
]
25+
}
26+
],
27+
28+
sidebar: [
29+
{
30+
text: 'Getting Started',
31+
collapsed: false,
32+
items: [
33+
{text: 'Introduction', link: '/docs/'},
34+
{text: 'Getting Started', link: '/docs/getting-started'},
35+
{text: 'Basic Usage', link: '/docs/basic-usage'},
36+
{text: 'Configuration', link: '/docs/configuration'},
37+
]
38+
},
39+
{
40+
text: 'Pipelines',
41+
collapsed: false,
42+
link: '/docs/pipelines',
43+
items: [
44+
{text: 'Text Classification', link: '/docs/text-classification'},
45+
{text: 'Fill Mask', link: '/docs/fill-mask'},
46+
{text: 'Zero Shot Classification', link: '/docs/zero-shot-classification'},
47+
{text: 'Question Answering', link: '/docs/question-answering'},
48+
{text: 'Token Classification', link: '/docs/token-classification'},
49+
{text: 'Feature Extraction', link: '/docs/feature-extraction'},
50+
{text: 'Text to Text Generation', link: '/docs/text-to-text-generation'},
51+
{text: 'Translation', link: '/docs/translation'},
52+
{text: 'Summarization', link: '/docs/summarization'},
53+
{text: 'Text Generation', link: '/docs/text-generation'},
54+
]
55+
},
56+
{
57+
text: 'Advanced Usage',
58+
collapsed: false,
59+
items: [
60+
{text: 'Auto Models', link: '/docs/auto-models'},
61+
{text: 'Auto Tokenizers', link: '/docs/auto-tokenizers'},
62+
]
63+
},
64+
{
65+
text: 'Utilities',
66+
collapsed: false,
67+
items: [
68+
{text: 'Generation', link: '/docs/generation'},
69+
]
70+
}
71+
],
72+
73+
socialLinks: [
74+
{icon: 'github', link: 'https://github.com/CodeWithKyrian/transformers-php'},
75+
{icon: 'twitter', link: 'https://twitter.com/CodeWithKyrian'}
76+
],
77+
78+
footer: {
79+
message: 'Released under the MIT License.',
80+
copyright: 'Copyright © 2024 <a href="https://github.com/yyx990803">Kyrian Obikwelu</a>'
81+
},
82+
83+
editLink: {
84+
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
85+
text: 'Edit this page on GitHub'
86+
},
87+
88+
search: {
89+
provider: 'local'
90+
}
91+
},
92+
cleanUrls: true,
93+
lastUpdated: true,
94+
markdown: {
95+
theme: {light: 'min-light', dark: 'min-dark'},
96+
}
97+
})

docs/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Transformers PHP Documentation
2+
3+
Welcome to the official documentation for Transformers PHP. You can find the online version of this documentation
4+
at [https://codewithkyrian.github.io/transformers-docs/](https://codewithkyrian.github.io/transformers-docs/).
5+
6+
## Contributing
7+
8+
If you would like to contribute to the documentation, create a pull request with your changes. The documentation is
9+
written in Markdown so it should be easy to understand and contribute to.

docs/bun.lockb

44.6 KB
Binary file not shown.

docs/docs/basic-usage.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Basic Usage
6+
7+
The quickest and most straightforward way to get started with Transformers PHP is through the pipelines API. If you're
8+
familiar with the Transformers library for Python, you'll find this approach quite similar. It's a user-friendly API
9+
that bundles a model with all the necessary preprocessing and postprocessing steps for a specific task.
10+
11+
## Creating a Pipeline
12+
13+
To create a pipeline, you need to specify the task you want to use it for. For example, if you want to use a pipeline
14+
for sentiment analysis, you can create a pipeline like this:
15+
16+
```php
17+
use function Codewithkyrian\Transformers\Pipelines\pipeline;
18+
19+
$classifier = pipeline('sentiment-analysis');
20+
```
21+
22+
The first time you run this, Transformers PHP will download and cache the default pre-trained model for sentiment
23+
analysis on-the-fly. This initial setup might take a bit, but subsequent runs will be much faster.
24+
25+
> [!TIP]
26+
> To avoid any wait time or possible hiccups with on-the-fly model downloads, it's a good idea to pre-download
27+
> your models. Check out the section on [pre-downloading models](/docs/getting-started#pre-download-models) for how to
28+
> do this.
29+
30+
## Using a different model
31+
32+
Each task has a default model it uses for inference. You can however specify a different model to use:
33+
34+
```php
35+
$classifier = pipeline('sentiment-analysis', 'Xenova/bert-base-multilingual-uncased-sentiment');
36+
```
37+
38+
You can also specify if the quantized model should be used or not (the default is `true`):
39+
40+
```php
41+
$classifier = pipeline('sentiment-analysis', quantized: false);
42+
```
43+
44+
## Using the Pipeline
45+
46+
Now that you have your pipeline, using it is as simple as calling a function. Just provide the text you want to analyze:
47+
48+
```php
49+
$result = $classifier('I love Transformers PHP!');
50+
```
51+
52+
And voilà, you'll get the sentiment analysis result:
53+
54+
```php
55+
['label' => 'POSITIVE', 'score' => 0.9995358059835]
56+
```
57+
58+
You're not limited to one text at a time; you can also pass an array of texts to get multiple analyses:
59+
60+
```php
61+
$results = $classifier([
62+
'I love Transformers PHP!',
63+
'I hate Transformers PHP!',
64+
]);
65+
```
66+
67+
The output will give you a sentiment score for each text:
68+
69+
```php
70+
[
71+
['label' => 'POSITIVE', 'score' => 0.99980061678407],
72+
['label' => 'NEGATIVE', 'score' => 0.99842234422764],
73+
]
74+
```
75+
76+
## What's Next?
77+
78+
Now that you've seen how easy it is to use Transformers PHP, you might want to explore the other features it offers.
79+
Check out the advanced usage section to learn about more advanced features like customizing the
80+
pipelines, using the models directly, using tokenizers, and more.

0 commit comments

Comments
 (0)