yipengsun's picture
Model card: wording
0e4ef20 verified
|
Raw History Blame Contribute Delete
8.53 kB
metadata
license: apache-2.0
base_model: google/gemma-4-31B
language:
  - en
tags:
  - lora
  - style-transfer
  - academic-writing
  - rewriting
pipeline_tag: text-generation
extra_gated_prompt: >-
  Access is granted by manual approval. Please say briefly who you are and how
  you plan to use the model.
extra_gated_fields:
  Name: text
  Affiliation: text
  Intended use: text

Write like Kaiming and Saining

LoRA adapters for the pretrained base model google/gemma-4-31B that rewrite a paragraph of an ML paper in the writing style of Kaiming He or Saining Xie.

You give the model a draft paragraph. It returns a rewrite of that paragraph with the same content. The model aims for short direct sentences, clear transitions and concrete claims.

Base model only. We trained these adapters on the pretrained base model google/gemma-4-31B. They do not work with the instruction-tuned model (google/gemma-4-31B-it) or with any other checkpoint. Load the adapters on google/gemma-4-31B only.

This is a personal research project. Kaiming He and Saining Xie did not take part in it, and they do not endorse it.

Versions

The repository holds three adapters. All of them use the same base model and the same prompt format. Earlier adapters (v5g-epoch1, v5g-epoch2) were retired; they remain in the repository history.

New: v5f-v9r8e2-mix05/. This adapter is an exact weight-space merge of two adapters: half of v5f and half of a newer rank-8 adapter trained on data that keeps strong rewrites (see Training). It has rank 72 and loads with the same code. It rewrites more boldly than v6-epoch4 but less wildly than v5f. In a blind reading of 24 held-out passages against v5f, v6-epoch4 and the rank-8 adapter alone, it had the best average rank. Use it when you want real sentence-level rewrites, and check every claim.

Conservative choice: v6-epoch4/. We trained it on a filtered data set (see Training). It changes facts least often and keeps the paragraph structure most reliably, but it often edits at the word level. One weakness: when the input is long and wordy, v6-epoch4 often keeps most of it instead of shortening it.

Strength Folder What it does When to use it
Light v6-epoch4/ Makes careful edits. The sentence structure often stays the same. You want light polishing and a low risk of changes in meaning.
Medium-strong v5f-v9r8e2-mix05/ Rewrites full sentences; shortens wordy drafts and expands terse ones. You want real rewrites in the target style.
Strong v5f/ Makes the largest changes and restructures whole paragraphs. It sometimes changes facts. You want bold alternatives and you will check every claim.

A stronger adapter gives more varied and more fluent rewrites, but it also has a higher risk of changes in meaning.

Training

  • Base model: google/gemma-4-31B (pretrained base, not the instruction-tuned model).
  • LoRA: rank 64, alpha 64, on all attention and MLP projections of the language model (q/k/v/o_proj, gate/up/down_proj).
  • Optimizer: learning rate 2e-4, context length 32k tokens.
  • Data: papers by Kaiming He and Saining Xie from arXiv. Each training pair maps an AI-written version of a passage to the original text by the author. The passages are sentences, paragraphs, sections and full papers. The data set has approximately 22k pairs.
  • Epochs: v5f trained for 4 epochs.
  • v6-epoch4: the same recipe (with a slightly larger pair set) for 4 epochs, on a filtered subset of the pairs. We kept a pair only if its numbers, citations, references and math are identical on both sides, it has the same number of paragraphs on both sides, and the target length is 0.80 to 1.25 times the input length. This kept approximately 11.6k of the 22k pairs. The filter removes pairs that teach the model to add or delete content.
  • v5f-v9r8e2-mix05: we first trained a rank-8 adapter (alpha 8) for 2 epochs on a larger set of approximately 29k pairs. That set drops only pairs whose target is nearly a copy of the input, so it keeps strong rewrites, including shortening and expansion. We then merged it with v5f in weight space: dW = 0.5 * dW_v5f + 0.5 * dW_rank8. We stored the merge exactly by concatenating the LoRA factors (rank 64 + 8 = 72, alpha 72). Merge weights from 0.3 to 0.7 read about the same. Scaling the merged update up (for example by 1.3) made the outputs worse.

The model was not trained on chat or instruction data. Use the fixed prompt below; free-form instructions do not work.

Prompt format

<style: {person}>
Rewrite the following text.

{your paragraph}

{person} is Kaiming He or Saining Xie. Put the BOS token first. Do not add a chat template. The model writes the rewrite after the blank line and stops with EOS.

Recommended sampling: temperature=0.7, top_p=0.95, top_k=0. Generate 8 to 32 samples per paragraph and select the best ones.

Usage

The adapters are plain safetensors files (lora_state.safetensors) with a small lora_meta.json. They are not in PEFT format. The script below merges an adapter into the base weights and then generates text with transformers. The base model in bf16 needs approximately 62 GB of GPU memory.

import json, re, torch
from huggingface_hub import snapshot_download
from safetensors.torch import load_file
from transformers import AutoModelForCausalLM, AutoTokenizer

REPO = "yipengsun/write-like-kaiming-and-saining"
VERSION = "v5f-v9r8e2-mix05"  # or "v6-epoch4", "v5f"

lora_dir = snapshot_download(REPO, allow_patterns=[f"{VERSION}/*"]) + f"/{VERSION}"
tok = AutoTokenizer.from_pretrained("google/gemma-4-31B")
model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-4-31B", torch_dtype=torch.bfloat16, device_map="auto")

# Merge the LoRA: W <- W + (alpha / rank) * B @ A
meta = json.load(open(f"{lora_dir}/lora_meta.json"))
sd = load_file(f"{lora_dir}/lora_state.safetensors")
scale = meta["alpha"] / meta["rank"]
modules = dict(model.named_modules())
wrap = re.compile(r"(_fsdp_wrapped_module\.|_checkpoint_wrapped_module\.|_orig_mod\.|_forward_module\.)")
pairs = {}
for key, value in sd.items():
    key = wrap.sub("", key).replace(".default.weight", ".weight")
    side = "A" if key.endswith(".lora_A.weight") else "B"
    name = key.rsplit(".lora_", 1)[0]
    while name not in modules:  # strip outer prefixes until the name matches
        name = name.split(".", 1)[1]
    pairs.setdefault(name, {})[side] = value
assert len(pairs) == meta["n_tensors"] // 2
with torch.no_grad():
    for name, ab in pairs.items():
        w = modules[name].weight
        delta = ab["B"].to(w.device).float() @ ab["A"].to(w.device).float()
        w.copy_((w.float() + scale * delta).to(w.dtype))

draft = "In this paper we propose a novel method that is able to significantly improve the performance of ..."
prompt = f"<style: Kaiming He>\nRewrite the following text.\n\n{draft}\n\n"
ids = [tok.bos_token_id] + tok(prompt, add_special_tokens=False)["input_ids"]
ids = torch.tensor([ids], device=model.device)
out = model.generate(ids, max_new_tokens=2 * ids.shape[1], do_sample=True,
                     temperature=0.7, top_p=0.95, top_k=0, num_return_sequences=4)
for seq in out:
    print(tok.decode(seq[ids.shape[1]:], skip_special_tokens=True), "\n---")

To serve the model with vLLM or another engine, save the merged model with model.save_pretrained(...) and load that folder.

Limitations

Read every output before you use it. The model is a writing aid. It does not check facts.

  • Invented content. The model can change numbers, change definitions, remove qualifiers or add claims that the input does not support. This happens most often with v5f and with long inputs.
  • Copying. If the input is already well written, the model often returns it almost unchanged.
  • Long inputs. When you give a full paper, the model often stops before the conclusion. Some samples collapse to a single short paragraph. Rewrite one section or a few paragraphs at a time for the best results.
  • LaTeX. The model sometimes breaks math, citations or special characters. Compare the output with the input.
  • Scope. The training data contains only computer vision and machine learning papers by two authors. Other fields and other styles were not tested.

License

The adapters are released under Apache 2.0, the same license as the base model. Use of the base model follows its own license terms.