Sorts Google Drive files into class folders with a small neural net trained on folders you've already sorted.
Drive file ─► text ─► 384-number embedding ─► MLP ─► probability per class
(export or (PDF, (all-MiniLM-L6-v2, (384 → 128 → classes,
download) .docx, fixed, not trained) trained on your folders)
Docs…)
- Text: Docs and Slides are exported as plain text and Sheets as CSV (first sheet only). PDFs, .docx, and text files are downloaded and parsed. Photos, videos, installers, archives, and other types with no text are skipped. A PDF with no extractable text (a scan) is classified by its filename alone.
- Embedding: each file is split into 256-token chunks with the filename at the start of each one, because names like
CPE 2310 Lab 3.pdfare a strong signal. The chunks are embedded and the vectors averaged into one per file. At most the first 64 chunks are used. - Classifier: 384 → 128 (ReLU + dropout) → one output per class, trained with cross-entropy. Training holds out 20% of each class to report accuracy on files the model never saw, then retrains on all files for the saved model.
- Prediction: softmax gives the top guesses. Anything below the confidence threshold (default 60%) is left for you to sort by hand.
- Google Cloud. Use the same project as the Gmail API. Enable the Google Drive API. Under APIs & Services → Credentials, create an OAuth client ID of type Desktop app, download the JSON, and save it in this folder as
credentials.json. If the app is in Testing mode, your account must be listed as a test user. - Install.
python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt - Labels. Make a Drive folder called
Classeswith one subfolder per class, and put 10–20 already-sorted files in each. The subfolder names become the labels. Files in nested subfolders count toward their top-level class.
python main.py train # learn from Classes/ (or: train "Some Other Folder")
python main.py predict <file URL or ID> # top 3 guesses for one file
python main.py organize Inbox # dry run: what would move where
python main.py organize Inbox --apply # ask for confirmation, then move the confident files
python main.py undo # move the last --apply batch back- Folders can be given by name, ID, or URL.
rootmeans the top level of My Drive. organizeonly looks at files directly inside the folder, not in its subfolders.--threshold 0.8changes the confidence needed to sort a file automatically. The held-out report fromtrainshows how many files would be auto-sorted at a given threshold, and how many of those were right.- The first login asks for read-only access. The first
organize --applyopens the browser again to ask for full Drive access, which moving files requires.token.jsonis replaced automatically.
arena/ is a sandbox for running the whole workflow on your own disk. arena/Classes/ has four classes (Calculus, Digital Logic, English, Physics), each with 25 fictional student files: notes, homework, lab reports, and study guides, saved as .txt, .md, .docx, and .pdf. arena/Inbox/ has 14 unsorted files. Ten of them belong to a class, and four (a grocery list, a recipe, lease questions, and a résumé) belong to none.
python arena/make_arena.py # build arena/Classes and arena/Inbox (re-run to reset)
python main.py train arena/Classes --local
python main.py predict "arena/Inbox/HW 6.pdf" --local
python main.py organize arena/Inbox --local # dry run
python main.py organize arena/Inbox --local --apply # moves the files on disk
python main.py undo--localworks withtrain,predict, andorganize. With it, folders and files are paths on disk instead of Drive names or URLs.- There's only one
model.pt, so training on the arena replaces your Drive model.organize --applyrefuses to move Drive files with a locally trained model, and the reverse. Retrain before switching. - A local folder can't hold two files with the same name, so
organizeskips any file whose name is already taken in the target folder. Drive allows duplicate names. - The documents live as plain text in
arena/corpus/. There's one file per folder, and each document starts with a=== filename.ext ===line. To add documents, add sections. To add or rename a class, add or rename a corpus file. Then rebuild.
| File | What it is |
|---|---|
token.json |
Your Google login. Delete it to log in again. |
model.pt |
The trained MLP plus the class names and folder IDs. |
cache/ |
Per-file chunk text and chunk embeddings, reused until the file changes. |
moves.jsonl |
Log of every move, used by undo. |
Softmax always splits 100% across your classes, so a file that belongs to none of them can still come out with high confidence. In the arena, the grocery list, recipe, and lease questions stay below the threshold, but the résumé goes to Digital Logic at 72% because it's full of Verilog and FPGA terms. Before you run organize --apply on a mixed folder:
- Check the dry run first.
- Consider a
Classes/Othersubfolder with 10–20 files that don't belong to any class, so the model has somewhere to put them.
- RAG:
cache/*.npzalready holds each file's chunk text (chunks) and chunk vectors (vectors), which is what a vector store needs. - From scratch: the MLP is small enough to rewrite in plain NumPy, forward pass and backprop. Train both versions on the same data to check your gradients.