Skip to content

Commit d46649c

Browse files
authored
Fix code sample
1 parent cba9926 commit d46649c

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

README.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*This proposal is an early design sketch by ODML and Chrome built-in AI team to describe the problem below and solicit
44
feedback on the proposed solution. It has not been approved to ship in Chrome.*
55

6-
Proofreading is the process of examining a text carefully to find and correct errors such as grammar, spelling, and punctuation to generate an error-free text before it is published or shared. Browsers and operating systems are increasingly offering proofreading capability to help their users compose (examples: [Example](https://chrome.googleblog.com/2013/03/oodles-of-improvements-to-chromes-spell.html), [Example](https://support.apple.com/guide/mac-help/use-writing-tools-mchldcd6c260/mac)).
6+
Proofreading is the process of examining a text carefully to find and correct errors such as grammar, spelling, and punctuation to generate an error-free text before it is published or shared. Browsers and operating systems are increasingly offering proofreading capability to help their users compose (examples: [Example](https://chrome.googleblog.com/2013/03/oodles-of-improvements-to-chromes-spell.html), [Example](https://support.apple.com/guide/mac-help/use-writing-tools-mchldcd6c260/mac)).
77

8-
Web applications can also benefit from such proofreading capability. This proposal introduces a new JavaScript API which, by exposing high-level functionality of a language model, corrects and labels a variety of errors from user input. Specifically, the proposed proofreading API in this explainer exposes three specific higher-level functionalities for proofreading:
8+
Web applications can also benefit from such proofreading capability. This proposal introduces a new JavaScript API which, by exposing high-level functionality of a language model, corrects and labels a variety of errors from user input. Specifically, the proposed proofreading API in this explainer exposes three specific higher-level functionalities for proofreading:
99

1010

1111
1. Error Correction: Correct input text by the user
@@ -50,7 +50,7 @@ const proofreader = await Proofreader.create({
5050
const corrections = await proofreader.proofread("I seen him yesterday at the store, and he bought two loafs of bread.");
5151
```
5252

53-
`proofread()` corrects the input text and returns a list of corrections made. Additional proofreading features can be configured using includeCorrectionTypes and `includeCorrectionExplanations`. When `includeCorrectionTypes` is set to `true`, `proofread()` will provide an error type label for each correction made to each error. When `includeCorrectionExplanations` is set to `true`, `proofread()` will provide an annotation for each error with a plain language explanation.
53+
`proofread()` corrects the input text and returns a list of corrections made. Additional proofreading features can be configured using includeCorrectionTypes and `includeCorrectionExplanations`. When `includeCorrectionTypes` is set to `true`, `proofread()` will provide an error type label for each correction made to each error. When `includeCorrectionExplanations` is set to `true`, `proofread()` will provide an annotation for each error with a plain language explanation.
5454

5555
Detailed design for the corrections output is [discussed later](#proofreading-correction-output).
5656

@@ -104,7 +104,7 @@ const proofreader = await proofreader.create({
104104
```
105105

106106
### Testing available options before creation
107-
The proofreading API is customizable during the `create()` calls, with various options including the language option above. All options are given in more detail in the [later section](#full-api-surface-in-web-idl).
107+
The proofreading API is customizable during the `create()` calls, with various options including the language option above. All options are given in more detail in the [later section](#full-api-surface-in-web-idl).
108108

109109
However, not all models will necessarily support every language and it might require a download to get the appropriate fine-tuning or other collateral necessary on the first use.
110110

@@ -132,7 +132,7 @@ if (supportsOurUseCase !== "unavailable") {
132132
console.log(await proofreader.proofread(editBoxEl.textContent));
133133
} else {
134134
// Either the API overall, or the combination of correction-with-labels with
135-
// English input, is not available.
135+
// English input, is not available.
136136
// Handle the failure / run alternatives.
137137
}
138138
```
@@ -200,7 +200,7 @@ dictionary ProofreadCorrection {
200200
unsigned long long endIndex;
201201
DOMString correction;
202202
CorrectionType type; // exists if proofreader.includeCorrectionTypes === true
203-
DOMString explanation; // exists if proofreader.includeCorrectionExplanations === true
203+
DOMString explanation; // exists if proofreader.includeCorrectionExplanations === true
204204
}
205205

206206
enum CorrectionType { "spelling", "punctuation", "capitalization", "preposition", "missing-words", "grammar" };
@@ -216,22 +216,24 @@ Example usage of the output to highlight error in input:
216216
217217
```js
218218
let inputRenderIndex = 0;
219+
219220
for (const correction of corrections) {
220-
// render part of input that has no error
221-
if (startIndex > inputRenderIndex) {
221+
// Render part of input that has no error.
222+
if (correction.startIndex > inputRenderIndex) {
222223
const unchangedInput = document.createElement('span');
223224
unchangedInput.textContent = input.substring(inputRenderIndex, correction.startIndex);
224225
editBox.append(unchangedInput);
225226
}
226-
// render part of input that is an error, highlight in red
227+
// Render part of input that has an error and highlight as such.
227228
const errorInput = document.createElement('span');
228229
errorInput.textContent = input.substring(correction.startIndex, correction.endIndex);
229-
errorInput.classList.add('red');
230+
errorInput.classList.add('error');
230231
editBox.append(errorInput);
231232
inputRenderIndex = correction.endIndex;
232233
}
233-
// render rest of input that has no error
234-
if (inputRenderIndex != input.length){
234+
235+
// Render rest of input that has no error.
236+
if (inputRenderIndex !== input.length){
235237
const unchangedInput = document.createElement('span');
236238
unchangedInput.textContent = input.substring(inputRenderIndex, input.length);
237239
editBox.append(unchangedInput);
@@ -246,15 +248,15 @@ interface ProofreaderFactory {
246248
static Promise<AIAvailability> availability(optional ProofreaderCreateCoreOptions options = {});
247249

248250
Promise<ProofreadResult> proofread(DOMString input);
249-
ReadableStream proofreadStreaming(DOMString input);
251+
ReadableStream proofreadStreaming(DOMString input);
250252

251253
// whether to provide correction types for each correction as part of the proofreading result.
252254
readonly attribute boolean includeCorrectionTypes;
253255
// whether to provide explanations for each correction as part of the proofreading result.
254256
readonly attribute boolean includeCorrectionExplanations;
255257
readonly attribute DOMString? correctionExplanationLanguage;
256258
readonly attribute FrozenArray<DOMString>? expectedInputLanguages;
257-
259+
258260
undefined destroy();
259261
};
260262

@@ -283,13 +285,13 @@ dictionary ProofreadCorrection {
283285
DOMString explanation;
284286
}
285287

286-
enum CorrectionType {
287-
"spelling",
288-
"punctuation",
289-
"capitalization",
290-
"preposition",
291-
"missing-words",
292-
"grammar"
288+
enum CorrectionType {
289+
"spelling",
290+
"punctuation",
291+
"capitalization",
292+
"preposition",
293+
"missing-words",
294+
"grammar"
293295
};
294296
```
295297
@@ -311,8 +313,8 @@ The [spellcheck](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attrib
311313
For more sophisticated browser integrated proofreading features, it’s an open question how to address the potential conflicts. For example, for browser extensions, one option is for web developers to detect the presence of certain extensions and then decide the behavior of their own proofreading feature.
312314
313315
### Customization with user-mutable dictionary
314-
While the proposed Proofreading API corrects user input based on general knowledge, there could be cases where users would prefer to ignore correcting certain proper names, acronyms, etc. For example, the proposed [Dictionary API](https://github.com/Igalia/explainers/pull/37) allows users to add and remove words from the browser’s custom dictionary to address special use cases.
316+
While the proposed Proofreading API corrects user input based on general knowledge, there could be cases where users would prefer to ignore correcting certain proper names, acronyms, etc. For example, the proposed [Dictionary API](https://github.com/Igalia/explainers/pull/37) allows users to add and remove words from the browser’s custom dictionary to address special use cases.
315317
316-
The Proofreading API can potentially allow users to specify a custom dictionary, and avoid correcting any words included in the dictionary.
318+
The Proofreading API can potentially allow users to specify a custom dictionary, and avoid correcting any words included in the dictionary.
317319
318320
However, in cases where ignoring certain words for correction could potentially change the meaning/structure of a sentence, it could be a bit tricky to proofread with pre-trained language models. Therefore, we are moving forward without integration with custom dictionaries until further exploration and evaluation is done. Nevertheless, we invite discussion of all of these APIs within the Web Machine Learning Community Group.

0 commit comments

Comments
 (0)